学无先后,达者为师

网站首页 编程语言 正文

Excel单元格空,设置为空字符串

作者:自由_free 更新时间: 2022-05-11 编程语言

Java使用hutool工具类解析Excel,单元格空,赋值为空字符串

		ExcelReader jobExcel = ExcelUtil.getReader(file.getInputStream(), 0);
		Sheet sheet = jobExcel.getSheet();
        int lastCellNum = sheet.getRow(Constants.EXCEL_READ_HEADER_ROW).getLastCellNum();
        int rowCount = jobExcel.getRowCount();
        for (int i = Constants.EXCEL_READ_ROW_VALUE; i < rowCount; i++) {
            Row row = sheet.getRow(i);
            for (int cellNum = 0; cellNum < lastCellNum; cellNum++) {
                row.getCell(cellNum, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
            }
        }
        List<List<Object>> read = jobExcel.read(1);

Pom文件

		<dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>5.0.0</version>
        </dependency>

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.11</version>
        </dependency>

原文链接:https://blog.csdn.net/weixin_49194846/article/details/124677377

栏目分类
最近更新