当前位置:网站首页>Easyexcel read file

Easyexcel read file

2022-06-26 01:47:00 NewBee. Mu

public XSSFSheet bulkLoad(MultipartFile file) {
    
        try {
    
            InputStream inputStream = new ByteArrayInputStream(file.getBytes());
            XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
            XSSFSheet sheet = workbook.getSheetAt(0);
            // Determine whether it is a template document 
            XSSFRow row1 = sheet.getRow(0);
            XSSFCell cell = row1.getCell(0);
            cell.setCellType(CellType.STRING);
            String stringCellValue = cell.getStringCellValue();
            int physicalNumberOfCells = row1.getPhysicalNumberOfCells();
            if (!" ID number ".equals(stringCellValue) || physicalNumberOfCells != 10){
    
                return null;
            }
            return sheet;
        } catch (IOException | StringIndexOutOfBoundsException e) {
    
            return null;
        }
    }

This method performs template verification , Verify whether the first row and the first column are ID number , Is there a total of 10 A title , If not , There is a problem with the template

 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();
            // For the first i Row data 
            row = sheet.getRow(i);
            if (row == null) {
    
                continue;
            }
            // The value of the first column 
            String value= StringTrim(row.getCell(0).getStringCellValue());
            .
            .
            .
            .
            .
            .
        }
    }

Here you can traverse to get excel The values in the table and deal with them

原网站

版权声明
本文为[NewBee. Mu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206252358200274.html