错误发生在保存包时:/xl/sharedStrings.xml 部分无法保存在与编组程序的流中。

huangapple go评论91阅读模式
英文:

Error occurs while saving the package : The part /xl/sharedStrings.xml fail to be saved in the stream with marshaller

问题

在从Java代码将大型.xlsx文件流式传输到浏览器时,我遇到了一个异常。

异常:保存失败:在保存包时出现错误:

部件/xl/sharedStrings.xml无法使用编组器org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@32c7a1ed保存在流中。

这个问题发生在下载时间较长的文件上,对于下载时间较短的其他文件,一切正常运行。

英文:

While streaming a large .xlsx file to the browser from java code I am getting an exception.

Exception: Fail to save: an error occurs while saving the package:

The part /xl/sharedStrings.xml fail to be saved in the stream with marshaller org.apache.poi.openxml4j.opc.internal.marshallers.DefaultMarshaller@32c7a1ed.

This issue is occurring for the files which are taking long time to download, for other files which are taking short time to download are working fine.

答案1

得分: 1

遇到了同样的问题。以下是我解决的方法:

将 Workbook 类更改为 SXSSFWorkbook:

Workbook wb = new SXSSFWorkbook();

如果你使用了自动调整列宽(就像我一样),在 Sheet 对象中添加以下调用:

sheet.trackAllColumnsForAutoSizing();

非常重要!不要忘记销毁 Workbook,否则临时文件将不会被删除:

wb.write(response.outputStream);
response.outputStream.close();
wb.dispose();

更多信息请参见这里

英文:

Had the same problem. Here is how I solved:

Change the Workbook class to SXSSFWorkbook:

Workbook wb = new SXSSFWorkbook();

If you have autosize (like I did), add the following call to the Sheet object:

sheet.trackAllColumnsForAutoSizing();

Very important! Don't forget to dispose the Workbook, otherwise temp files will NOT be deleted:

wb.write(response.outputStream);
response.outputStream.close();
wb.dispose();

More info here

huangapple
  • 本文由 发表于 2020年9月29日 17:20:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/64116589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定