java - JAVA APACHE POI:出现“我们发现 *.xlsx 中的某些内容存在问题。您是否希望我们尽可能多地尝试恢复它”错误
问题描述
我们正在尝试生成 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");
推荐阅读
- javascript - Http 状态码 412 - 前提条件失败
- git - 推送到 Gitlab 合并请求远程无法识别来自 rebase 的更改
- c# - 带有多个where条件错误的sql删除语句
- javascript - React:如何在第一次渲染时跳过 useEffect
- json - 任何建议在不同列的 csv 中从网站写入 json 数据抓取
- python - 如何使用 loc on 过滤多个值
- process - 为什么这段代码不能解决临界区问题?
- excel - VBA excel函数
- excel - 动态引用不断被覆盖的数据的图表
- python - 读取/写入时 modbus 错误无法连接到 ModbusTcpClient