localizer
ljw 2025-10-13 11:10:17 +08:00
parent ae3c856b28
commit 3fc015d6d9
1 changed files with 14 additions and 14 deletions

View File

@ -68,7 +68,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
SXSSFSheet sheet = (SXSSFSheet) writer.getSheet(); SXSSFSheet sheet = (SXSSFSheet) writer.getSheet();
// 手动设置列宽,确保标题和数据内容都能完整显示 // 手动设置列宽,确保标题和数据内容都能完整显示
int columnCount = sheet.getRow(0).getLastCellNum(); /*int columnCount = sheet.getRow(0).getLastCellNum();
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
String headerText = ""; String headerText = "";
int maxContentLength = 0; int maxContentLength = 0;
@ -103,21 +103,21 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
// 设置列宽,确保标题和内容都能完整显示 // 设置列宽,确保标题和内容都能完整显示
sheet.setColumnWidth(i, Math.max(calculatedWidth, currentWidth)); sheet.setColumnWidth(i, Math.max(calculatedWidth, currentWidth));
} }*/
// 尝试自动调整列宽 // 尝试自动调整列宽
// try { try {
// sheet.trackAllColumnsForAutoSizing(); sheet.trackAllColumnsForAutoSizing();
// writer.autoSizeColumnAll(); writer.autoSizeColumnAll();
// } catch (Exception e) { } catch (Exception e) {
// log.warn("自动调整列宽失败,使用手动设置的列宽", e); log.warn("自动调整列宽失败,使用手动设置的列宽", e);
// } }
//response为HttpServletResponse对象 //response为HttpServletResponse对象
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
//设置文件名,支持中文文件名 //设置文件名,支持中文文件名
try { try {
String encodedFileName = java.net.URLEncoder.encode(fileName, "UTF-8"); String encodedFileName = java.net.URLEncoder.encode(fileName, "UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName + ";filename*=UTF-8''" + encodedFileName); response.setHeader("Content-Disposition", "attachment;filename=" + encodedFileName);
} catch (Exception e) { } catch (Exception e) {
// 如果编码失败,使用默认文件名 // 如果编码失败,使用默认文件名
response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); response.setHeader("Content-Disposition", "attachment;filename=file.xlsx");