easyexcel使用

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

复制代码
		Path excelFilePath = Paths.get(intput);

		// Use WorkbookFactory to create a Workbook object from the file
		Workbook workbook = WorkbookFactory.create(excelFilePath.toFile());

		// Iterate over each sheet in the workbook
		for (Sheet sheet : workbook) {
			// Print sheet name
			System.out.println("Sheet Name: " + sheet.getSheetName());

			// Get the number of rows in the sheet
			int rowCount = sheet.getPhysicalNumberOfRows();
			System.out.println("Number of Rows: " + rowCount);
		}

		// Close the workbook to release resources
		workbook.close();
	}

2.读取第一行

复制代码
	EasyExcel.read(inputPath,clazz, new ReadListener<ExcelChecker>() {
			@Override
			public void invoke(ExcelChecker data, AnalysisContext context) {
				firstData[0] = data;
				throw new ExcelAnalysisStopException("只读取第一行数据"); //只能通过异常打断
			}

			@Override
			public 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();
相关推荐
撩得Android一次心动几秒前
Android LiveData 全面解析:使用Java构建响应式UI【源码篇】
android·java·android jetpack·livedata
组合缺一4 分钟前
Solon AI (Java) v3.9 正式发布:全能 Skill 爆发,Agent 协作更专业!仍然支持 java8!
java·人工智能·ai·llm·agent·solon·mcp
MSTcheng.8 分钟前
【C++】C++11新特性(二)
java·开发语言·c++·c++11
一 乐12 分钟前
校园二手交易|基于springboot + vue校园二手交易系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端
KIKIiiiiiiii13 分钟前
微信个人号API二次开发中的解决经验
java·人工智能·python·微信
80530单词突击赢14 分钟前
SpringBoot整合SpringMVC全解析
java·spring boot·后端
vx1_Biye_Design24 分钟前
基于Spring Boot+Vue的学生管理系统设计与实现-计算机毕业设计源码46223
java·vue.js·spring boot·spring·eclipse·tomcat·maven
vx_Biye_Design25 分钟前
基于Spring Boot+vue的湖北旅游景点门票预约平台的设计--毕设附源码29593
java·vue.js·spring boot·spring cloud·servlet·eclipse·课程设计
hay_lee43 分钟前
Spring AI实现对话聊天-流式输出
java·人工智能·ollama·spring ai
Hx_Ma161 小时前
SpringBoot数据源自动管理
java·spring boot·spring