• easyexcel读取文件


    public XSSFSheet bulkLoad(MultipartFile file) {
            try {
                InputStream inputStream = new ByteArrayInputStream(file.getBytes());
                XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
                XSSFSheet sheet = workbook.getSheetAt(0);
                //判断是否为模板文档
                XSSFRow row1 = sheet.getRow(0);
                XSSFCell cell = row1.getCell(0);
                cell.setCellType(CellType.STRING);
                String stringCellValue = cell.getStringCellValue();
                int physicalNumberOfCells = row1.getPhysicalNumberOfCells();
                if (!"身份证号".equals(stringCellValue) || physicalNumberOfCells != 10){
                    return null;
                }
                return sheet;
            } catch (IOException | StringIndexOutOfBoundsException e) {
                return null;
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    这个方法是进行模板校验,校验第一行第一列是不是身份证号,总共是不是有10个标题,如果不是,那就是模板出现了问题

     public void bulkLoadContent(XSSFSheet sheet) {
            Integer rows = sheet.getPhysicalNumberOfRows();
            XSSFRow row;
            PatientInformation patientInformation = new PatientInformation();
            RegisterInformation registerInformation = new RegisterInformation();
            BasicInformationImportLog importLog = new BasicInformationImportLog();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            boolean flag;
            for (int i = 1; i < rows; i++) {
                flag = true;
                StringBuffer buffer = new StringBuffer();
                //获取第i行的数据
                row = sheet.getRow(i);
                if (row == null) {
                    continue;
                }
                //第一列的值
                String value= StringTrim(row.getCell(0).getStringCellValue());
                .
                .
                .
                .
                .
                .
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    这里就可以遍历获取到excel表格中的值并对他们做处理了

  • 相关阅读:
    Linux—进程间通信之System V共享内存
    35、CSS进阶——画布背景
    查找算法-二分查找法(Binary Search)
    Deno完整教程
    Unity AVPro Video 加载视频第一秒图片与例子
    【BLE】蓝牙抓包器 Ellisys 使用说明
    Python从0到100(二):Python语言介绍及第一个Pyhon程序
    charCodeAt() 方法了解和用法&unicode编码表
    leetcode1610. 可见点的最大数目(java)
    docker从入门到入土
  • 原文地址:https://blog.csdn.net/NewBeeMu/article/details/125443368