英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论