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();
相关推荐
HoneyMoose2 小时前
Jenkins Cloudflare 部署提示错误
java·servlet·jenkins
阿丰资源3 小时前
基于SpringBoot的物流信息管理系统设计与实现(附资料)
java·spring boot·后端
Predestination王瀞潞3 小时前
Java EE3-我独自整合(第四章:Spring bean标签的常见配置)
java·spring·java-ee
overmind3 小时前
oeasy Python 121[专业选修]列表_多维列表运算_列表相加_列表相乘
java·windows·python
资深数据库专家3 小时前
总账EBS 应用服务器1 的监控分析
java·网络·数据库
房开民3 小时前
可变参数模板
java·开发语言·算法
t***5443 小时前
如何在现代C++中更有效地应用这些模式
java·开发语言·c++
_深海凉_3 小时前
LeetCode热题100-最小栈
java·数据结构·leetcode
不知名的忻3 小时前
Morris遍历(力扣第99题)
java·算法·leetcode·morris遍历
daidaidaiyu3 小时前
一文学习入门 ThingsBoard 开源物联网平台
java·mqtt·spring