|
@@ -36,7 +36,7 @@ public class ExcelDownloadSrv {
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass().getName());
|
|
|
|
|
|
// 每个单元格最多存放多少行数据
|
|
|
- private final int SHEET_MAX_SIZE = 1;
|
|
|
+ private final int SHEET_MAX_SIZE = 2;
|
|
|
|
|
|
/**
|
|
|
* 下载excel 时 设置 httpServletResponse
|
|
@@ -314,6 +314,7 @@ public class ExcelDownloadSrv {
|
|
|
sheetAmount = listSize / sheetMaxSize + 1;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
// 工作表
|
|
|
for (int i = 0; i < sheetAmount; i++) {
|
|
|
// 当前页数(从0开始)
|
|
@@ -327,6 +328,27 @@ public class ExcelDownloadSrv {
|
|
|
sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
|
|
+ // 当前页数所对应的行数
|
|
|
+ int currentSheetRowAmount = 0;
|
|
|
+ if (listSize < sheetMaxSize * sheetIndex) {
|
|
|
+ currentSheetRowAmount = listSize - sheetMaxSize * currentSheetIndex;
|
|
|
+ } else {
|
|
|
+ currentSheetRowAmount = sheetMaxSize;
|
|
|
+ }
|
|
|
+ // 单独应用样式
|
|
|
+ if (excelStyleMap != null) {
|
|
|
+ for (String column : excelStyleMap.keySet()) {
|
|
|
+ // 指定列宽
|
|
|
+ int styleColumnWidth = excelStyleMap.getIntValueSafely(column, ExcelStyleMap.STYLE_COLUMN_WIDTH, 0);
|
|
|
+ List<String> columns = new ArrayList<>(data.keySet());
|
|
|
+ for (int j = 0, columnsSize = columns.size(); j < columnsSize; j++) {
|
|
|
+ if (columns.get(j).equals(column)) {
|
|
|
+ sheet.setColumnView(j, styleColumnWidth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 第一行
|
|
|
int firstRow = 0;
|
|
|
//填充表头
|
|
|
int headerColumn = 0;
|
|
@@ -334,17 +356,12 @@ public class ExcelDownloadSrv {
|
|
|
Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
sheet.addCell(label);
|
|
|
List<String> colData = data.get(key);
|
|
|
- // 当前页数所对应的行数
|
|
|
- int currentSheetRowAmount = 0;
|
|
|
- if (listSize < sheetMaxSize * sheetIndex) {
|
|
|
- currentSheetRowAmount = listSize - sheetMaxSize * currentSheetIndex;
|
|
|
- } else {
|
|
|
- currentSheetRowAmount = sheetMaxSize;
|
|
|
- }
|
|
|
- for (int q = 0; q < currentSheetRowAmount; q++) {
|
|
|
- int e = sheetMaxSize * currentSheetIndex;
|
|
|
- Label lb = new Label(headerColumn, q + 1, Checker.getStringValue(colData.get(e + q)), cellFormat);
|
|
|
- sheet.addCell(lb);
|
|
|
+ if(!Checker.isNone(colData)) {
|
|
|
+ for (int q = 0; q < currentSheetRowAmount; q++) {
|
|
|
+ int e = sheetMaxSize * currentSheetIndex;
|
|
|
+ Label lb = new Label(headerColumn, q + 1, Checker.getStringValue(colData.get(e + q)), cellFormat);
|
|
|
+ sheet.addCell(lb);
|
|
|
+ }
|
|
|
}
|
|
|
headerColumn++;
|
|
|
}
|
|
@@ -354,7 +371,7 @@ public class ExcelDownloadSrv {
|
|
|
for (ExcelCollectPojo pojo : collectList) {
|
|
|
String[] dataArr = pojo.getDataArr();
|
|
|
for (int r = 0, j = dataArr.length; r < j; r++) {
|
|
|
- Label lb2 = new Label(pojo.getCol() + r, pojo.getRow(), dataArr[r], cellFormat);
|
|
|
+ Label lb2 = new Label(pojo.getCol() + r, pojo.getRow() - sheetMaxSize * currentSheetIndex, dataArr[r], cellFormat);
|
|
|
sheet.addCell(lb2);
|
|
|
}
|
|
|
}
|
|
@@ -466,6 +483,13 @@ public class ExcelDownloadSrv {
|
|
|
sheet.getSettings().setDefaultColumnWidth(20);
|
|
|
sheet.getSettings().setDefaultRowHeight(30 * 20);
|
|
|
|
|
|
+ // 当前页数所对应的行数
|
|
|
+ int currentSheetRowAmount = 0;
|
|
|
+ if (listSize < sheetMaxSize * sheetIndex) {
|
|
|
+ currentSheetRowAmount = listSize - sheetMaxSize * currentSheetIndex;
|
|
|
+ } else {
|
|
|
+ currentSheetRowAmount = sheetMaxSize;
|
|
|
+ }
|
|
|
// 单独应用样式
|
|
|
if (excelStyleMap != null) {
|
|
|
for (String column : excelStyleMap.keySet()) {
|
|
@@ -483,23 +507,17 @@ public class ExcelDownloadSrv {
|
|
|
int firstRow = 0;
|
|
|
// 填充表头
|
|
|
int headerColumn = 0;
|
|
|
- // 遍历设置数据
|
|
|
for (String key : data.keySet()) {
|
|
|
Label label = new Label(headerColumn, firstRow, key, cellFormat);
|
|
|
sheet.addCell(label);
|
|
|
List<String> colData = data.get(key);
|
|
|
- // 当前页数所对应的行数
|
|
|
- int currentSheetRowAmount = 0;
|
|
|
- if (listSize < sheetMaxSize * sheetIndex) {
|
|
|
- currentSheetRowAmount = listSize - sheetMaxSize * currentSheetIndex;
|
|
|
- } else {
|
|
|
- currentSheetRowAmount = sheetMaxSize;
|
|
|
- }
|
|
|
- for (int q = 0; q < currentSheetRowAmount; q++) {
|
|
|
- // 之前所有页的数据汇总数量
|
|
|
- int beforePageAllAmount = sheetMaxSize * currentSheetIndex;
|
|
|
- Label lb = new Label(headerColumn, q + 1, Checker.getStringValue(colData.get(beforePageAllAmount + q)), cellFormat);
|
|
|
- sheet.addCell(lb);
|
|
|
+ if(!Checker.isNone(colData)) {
|
|
|
+ for (int q = 0; q < currentSheetRowAmount; q++) {
|
|
|
+ // 之前所有页的数据汇总数量
|
|
|
+ int beforePageAllAmount = sheetMaxSize * currentSheetIndex;
|
|
|
+ Label lb = new Label(headerColumn, q + 1, Checker.getStringValue(colData.get(beforePageAllAmount + q)), cellFormat);
|
|
|
+ sheet.addCell(lb);
|
|
|
+ }
|
|
|
}
|
|
|
headerColumn++;
|
|
|
}
|
|
@@ -507,7 +525,7 @@ public class ExcelDownloadSrv {
|
|
|
if (currentSheetIndex == sheetAmount - 1) {
|
|
|
if (!Checker.isNone(collectList)) {
|
|
|
for (CustomExcelItem item : collectList) {
|
|
|
- sheet.addCell(new Label(item.getColumn(), item.getRow(), item.getContent(), item.getCellFormat() == null ? cellFormat : item.getCellFormat()));
|
|
|
+ sheet.addCell(new Label(item.getColumn(), item.getRow() - sheetMaxSize * currentSheetIndex, item.getContent(), item.getCellFormat() == null ? cellFormat : item.getCellFormat()));
|
|
|
}
|
|
|
}
|
|
|
// 写入流
|