我们正在尝试生成 Excel 文件,但在尝试执行此代码时遇到了上述错误 -
我尝试过使用CreationHelper
,还尝试过FileOutputStream
。但是,似乎没有任何作用。我们正在使用 apache poi - 4.0.1
XSSFWorkbook xssfWorkbook = excelDownloadService.createSheetForBudget(type, campaignId, duration);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
xssfWorkbook.write(bos);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=Budget.Report_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddyy")) + ".xlsx");
xssfWorkbook.write(response.getOutputStream());
xssfWorkbook.close();
response.getOutputStream().flush();
response.getOutputStream().close();
最佳答案
我在其他地方使用 Name
属性来命名工作表。删除后,它起作用了。
final Name name = xssfWorkbook.createName();
name.setNameName("Summary.Report_" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMddyy")) + ".xlsx");
关于JAVA Apache POI : Getting a "We found a problem with some content in *.xlsx. Do you want us to try to recover it as much as we can" error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60551302/