Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用easyexcel导出excel 再 #1282

Closed
xiangwbs opened this issue Apr 28, 2020 · 6 comments
Closed

用easyexcel导出excel 再 #1282

xiangwbs opened this issue Apr 28, 2020 · 6 comments
Assignees
Labels
bug Something isn't working developing This feature will be added in future releases development completed Development completed, waiting for release

Comments

@xiangwbs
Copy link

建议先去看文档
快速开始常见问题
触发场景描述
用easyexcel导出excel 再用easyexcel读取之前导出的excel
不管excel有几行
Integer totalRowNumber = readSheetHolder.getApproximateTotalRowNumber();
这条数据永远是1

@xiangwbs xiangwbs added the bug Something isn't working label Apr 28, 2020
@zhuangjiaju zhuangjiaju added the pending verification This problem needs to be confirmed label Apr 30, 2020
@dota17
Copy link
Contributor

dota17 commented May 6, 2020

调试了下代码,easyexcel在解析xml的时候会获取 dimension标签中ref的值作为行数。然后我运行了下demo中的simpleWrite(),发现生成的excel转化成xml后dimension标签中的信息不太对:
2020-05-06_102321
实际的excel内容是这样:
3
所以dimension标签 中的内容应该是 :dimension ref="A1:C11"

@dota17
Copy link
Contributor

dota17 commented May 7, 2020

这个问题是导出excel时使用了SXSSFWorkbook的原因,如果使用XSSFWorkbook就不会出错,参考SXSSFWorkbook的实现原理,通过这种流的方式生成excel的时候没有对xml中的dimension标签进行操作,所以导出之后再通过xml文件获取行数的时候就会出错,后续是不是可以考虑在导出excel后再增加一个修改dimension标签的操作,或者建议用户获取行数的时候自己数?

@zhuangjiaju
Copy link
Collaborator

@zhuangjiaju zhuangjiaju added developing This feature will be added in future releases and removed pending verification This problem needs to be confirmed labels Jun 9, 2020
@cdoer
Copy link

cdoer commented Sep 18, 2020

通过上述方案规避了此问题,不过需要通过反射获取XSSFSheet设置才行,代码如下:
没想到github的评论排版这么难用
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").registerWriteHandler(new AbstractWorkbookWriteHandler() {
@OverRide
public void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) {
super.afterWorkbookDispose(writeWorkbookHolder);
Sheet sheet = writeWorkbookHolder.getWorkbook().getSheetAt(0);
if(sheet instanceof SXSSFSheet){
SXSSFSheet sh = ((SXSSFSheet) sheet);
XSSFSheet _sh = (XSSFSheet) ReflectUtil.getFieldValue(sh,"_sh");
_sh.getCTWorksheet().getDimension().setRef("A1:" + CellReference.convertNumToColString(atomicMaxColSize.get()) + atomicRowSize.get());
}
}
}).build();

@zhuangjiaju
Copy link
Collaborator

后续版本会解决

@zhuangjiaju zhuangjiaju added the development completed Development completed, waiting for release label Sep 17, 2021
@zhuangjiaju
Copy link
Collaborator

已经在3.0.0-beta1 版本修复,beta版本会在一个月内升级成正式版。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working developing This feature will be added in future releases development completed Development completed, waiting for release
Projects
None yet
Development

No branches or pull requests

4 participants