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

标签 java apache-poi

我们正在尝试生成 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/

相关文章:

java - 如何删除 apache POI 单元格中字符串的整行基础

java - 将样式应用于单元格范围 - Apache POI

java - 告诉 Hibernate 从脏检查中忽略属性

java - Java Servlet 中的 ExecutorService

java - 如何从 Iterator<E> 创建无限 Stream<E>?

java - 在java中读取文件上传的内容

java - 如何检查 JPanel 是否包含 JLabel?

java - 获取所有字符串字段的值

java - 兴趣点 : not iterating through all excel row while inserting values to database

java - 将文件名放在括号内