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