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;
        }
  • 相关阅读:
    postgres column reference "id" is ambiguous
    网络 内网穿透frp
    odoo12 支付宝在线支付
    odoo 账号登录不上,重置密码也不管用
    odoo 取消保存提示
    聊聊redis分布式锁的8大坑 转载
    用 Keepalived+HAProxy 实现高可用负载均衡的配置方法 转载
    Nginx+keepalived 实现高可用,常用防盗链及动静分离配置 转载
    Git 实用技巧记录 转载:https://mp.weixin.qq.com/s/o6FvGfiG9b57xTeXlBzzQQ
    5 个冷门但非常实用的 Kubectl 使用技巧,99% 的人都不知道 https://mp.weixin.qq.com/s/h4_KRmsVSnlqCmIJh0altA
  • 原文地址:https://www.cnblogs.com/418836844qqcom/p/11284277.html
Copyright © 2011-2022 走看看