zoukankan      html  css  js  c++  java
  • JAVA 导入EXCLE,处理时间字段

    import com.fengshun.systemBusiness.dao.BloodRecordsDao;
    import com.fengshun.systemBusiness.entity.BloodRecords;
    import org.apache.poi.hssf.usermodel.HSSFDateUtil;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.ss.usermodel.Cell;
    import org.apache.poi.ss.usermodel.Row;
    import org.apache.poi.ss.usermodel.Sheet;
    import org.apache.poi.ss.usermodel.Workbook;
    import org.springframework.stereotype.Service;
    import org.springframework.web.multipart.MultipartFile;
    
    import javax.annotation.Resource;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    
    
    public List<BloodRecords> getList(InputStream fis) throws Exception {
            List<BloodRecords> list = new ArrayList<>();
            Workbook workbook = new HSSFWorkbook(fis);
            Sheet sheet;
            //获取sheet数量
            int number = workbook.getNumberOfSheets();
            for (int i = 0; i < number; i++) {
                sheet = workbook.getSheetAt(i);
                if (sheet == null) {
                    continue;
                }
                //循环行
                for (int j = 1; j < sheet.getLastRowNum(); j++) {
                    Row row = sheet.getRow(j);
                    Cell cell0 = row.getCell(0);
                    Cell cell1 = row.getCell(1);
                    Cell cell2 = row.getCell(2);
                    Cell cell3 = row.getCell(3);
                    Cell cell4 = row.getCell(4);
                    Cell cell5 = row.getCell(5);
                    Date date = HSSFDateUtil.getJavaDate(cell0.getNumericCellValue());
                    BloodRecords b0 = new BloodRecords();
                    b0.setPatientId("1503256397");
                    b0.setVisitId(2L);
                    b0.setCollectDate(date);
                    b0.setBloodValue(Double.valueOf(cell1.toString()));
                    b0.setDynamicBlood(true);
                    BloodRecords b1 = new BloodRecords();
                    b1.setPatientId("1804142342");
                    b1.setVisitId(1L);
                    b1.setCollectDate(date);
                    b1.setBloodValue(Double.valueOf(cell2.toString()));
                    b1.setDynamicBlood(true);
                    BloodRecords b2 = new BloodRecords();
                    b2.setPatientId("1611147489");
                    b2.setVisitId(2L);
                    b2.setCollectDate(date);
                    b2.setBloodValue(Double.valueOf(cell3.toString()));
                    b2.setDynamicBlood(true);
                    BloodRecords b3 = new BloodRecords();
                    b3.setPatientId("1805056176");
                    b3.setVisitId(1L);
                    b3.setCollectDate(date);
                    b3.setBloodValue(Double.valueOf(cell4.toString()));
                    b3.setDynamicBlood(true);
                    BloodRecords b4 = new BloodRecords();
                    b4.setPatientId("1804302808");
                    b4.setVisitId(1L);
                    b4.setCollectDate(date);
                    b4.setBloodValue(Double.valueOf(cell5.toString()));
                    b4.setDynamicBlood(true);
                    list.add(b0);
                    list.add(b1);
                    list.add(b2);
                    list.add(b3);
                    list.add(b4);
                }
            }
            fis.close();
            return list;
        }
  • 相关阅读:
    2018-06-15for与数组/for-in与数组/一维二维多维数组
    2018-06-14控制语句for+switch+while循环
    2018-06-13JS分支结构+转义符
    2018-06-12JavaScript基础知识1
    2018-06-11笔记
    2018-06-08CSS常用样式+浮动+定位+盒子模型
    2018-06-06Div+CSS基础理论
    2018-06-05表单结构
    2018-06-04表格结构+表格嵌套
    2018-06-02笔记
  • 原文地址:https://www.cnblogs.com/418836844qqcom/p/11284277.html
Copyright © 2011-2022 走看看