您的位置:首页 > 汽车 > 时评 > easyexcel使用

easyexcel使用

2024/9/19 9:46:57 来源:https://blog.csdn.net/weixin_42410730/article/details/140439419  浏览:    关键词:easyexcel使用

1.读取行总数只能使用poi

		Path excelFilePath = Paths.get(intput);// Use WorkbookFactory to create a Workbook object from the fileWorkbook workbook = WorkbookFactory.create(excelFilePath.toFile());// Iterate over each sheet in the workbookfor (Sheet sheet : workbook) {// Print sheet nameSystem.out.println("Sheet Name: " + sheet.getSheetName());// Get the number of rows in the sheetint rowCount = sheet.getPhysicalNumberOfRows();System.out.println("Number of Rows: " + rowCount);}// Close the workbook to release resourcesworkbook.close();}

2.读取第一行

	EasyExcel.read(inputPath,clazz, new ReadListener<ExcelChecker>() {@Overridepublic void invoke(ExcelChecker data, AnalysisContext context) {firstData[0] = data;throw new ExcelAnalysisStopException("只读取第一行数据"); //只能通过异常打断}@Overridepublic void doAfterAllAnalysed(AnalysisContext context) {}}).head(clazz).charset(StandardCharsets.UTF_8).sheet().headRowNumber(0).doRea()

3.读取csv默认支持该格式

4.csv处理数据内的换行符
@ContentStyle(wrapped = BooleanEnum.TRUE)
wrapp处理列值本身有可能出现换行的,因为csv默认以换行符为一条完整的行数据,但是如何数据本身也换行了,就需要特殊处理,即在数据外围增加"",此时解析的对象也需要增加属性
easyexcel本身支持的一些属性注解:https://blog.csdn.net/cccsssrrr/article/details/127813042?spm=1001.2014.3001.5502
5.csv数据行内前后有空格默认会被自动去掉,需要增加autotrim属性

	EasyExcel.read(reqDTO.getReadPath(), clz,new PageReadListener0(new ExecelCheckConsumer(this, callbackEvery), readBatchSize, this,callbackEvery)).charset(StandardCharsets.UTF_8).sheet().autoTrim(false) // 不自动去除首尾空格.doRead();

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com