gpt4 book ai didi

java - 如何摆脱用户尝试打开 Excel 电子表格时显示的警告消息?

转载 作者:行者123 更新时间:2023-11-29 07:28:11 26 4
gpt4 key购买 nike

我正在使用 Apache POI 库的 3.17 版在 Java 中创建 Excel 电子表格。当用户从服务器下载它并尝试打开电子表格时,会显示一条警告消息。我在想电子表格的格式不知何故不正确。我如何修复它以便用户不会看到该消息?请务必注意,电子表格可以正常打开,并且所有数据都在那里。

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet;

// Add rows and cells to spreadsheet

response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=sheet.xls");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);

ByteArrayOutputStream bos = new ByteArrayOutputStream();
workbook.write(bos);
bos.close();

try (InputStream stream = new ByteArrayInputStream(bos.toByteArray())) {
IOUtils.copy(stream, response.getOutputStream());
}

enter image description here

最佳答案

扩展名应该是.xlsx,而不是.xls

关于java - 如何摆脱用户尝试打开 Excel 电子表格时显示的警告消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47318431/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com