|
|
@ -860,21 +860,17 @@ public class ExcelCommonUtil {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tableData == null || tableData.isEmpty()) {
|
|
|
|
// 创建Excel工作簿
|
|
|
|
//throw new IllegalArgumentException("The list of records must not be empty.");
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
return;
|
|
|
|
// 创建一个Excel工作表
|
|
|
|
}
|
|
|
|
Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(tableData!=null && !tableData.isEmpty() ){
|
|
|
|
// 获取第一个Record的元数据以确定列名
|
|
|
|
// 获取第一个Record的元数据以确定列名
|
|
|
|
Record firstRecord = tableData.getFirst();
|
|
|
|
Record firstRecord = tableData.getFirst();
|
|
|
|
String[] headers = firstRecord.getColumnNames();
|
|
|
|
String[] headers = firstRecord.getColumnNames();
|
|
|
|
int columnCount = headers.length;
|
|
|
|
int columnCount = headers.length;
|
|
|
|
|
|
|
|
|
|
|
|
// 创建Excel工作簿
|
|
|
|
|
|
|
|
Workbook workbook = new XSSFWorkbook();
|
|
|
|
|
|
|
|
// 创建一个Excel工作表
|
|
|
|
|
|
|
|
Sheet sheet = workbook.createSheet("Sheet1");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建标题行
|
|
|
|
// 创建标题行
|
|
|
|
Row titleRow = sheet.createRow(0);
|
|
|
|
Row titleRow = sheet.createRow(0);
|
|
|
|
// 设置标题行的样式
|
|
|
|
// 设置标题行的样式
|
|
|
@ -931,6 +927,7 @@ public class ExcelCommonUtil {
|
|
|
|
int newColumnWidth = Math.max(minColumnWidth, columnWidth);
|
|
|
|
int newColumnWidth = Math.max(minColumnWidth, columnWidth);
|
|
|
|
sheet.setColumnWidth(i, newColumnWidth);
|
|
|
|
sheet.setColumnWidth(i, newColumnWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将工作簿写入文件
|
|
|
|
// 将工作簿写入文件
|
|
|
|
try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
|
|
|
|
try (FileOutputStream fileOut = new FileOutputStream(filePath)) {
|
|
|
|