瀏覽代碼

修复多行模板导出的bug

4.1.3.A
jueyue 9 年之前
父節點
當前提交
9448297f50
共有 2 個文件被更改,包括 12 次插入5 次删除
  1. +2
    -0
      README.md
  2. +10
    -5
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java

+ 2
- 0
README.md 查看文件

@@ -98,6 +98,8 @@ EasyPoi 文档
[EasyPoi-多行模板输出(New)](http://blog.afterturn.cn/?p=40) [EasyPoi-多行模板输出(New)](http://blog.afterturn.cn/?p=40)
[EasyPoi-校验集成](http://blog.afterturn.cn/?p=65)
-------------------------- --------------------------
EasyPoi 模板 表达式支持 EasyPoi 模板 表达式支持


+ 10
- 5
easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java 查看文件

@@ -415,7 +415,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
MergedRegionHelper mergedRegionHelper) throws Exception { MergedRegionHelper mergedRegionHelper) throws Exception {
//所有的cell创建一遍 //所有的cell创建一遍
for (int i = 0; i < rowspan; i++) { for (int i = 0; i < rowspan; i++) {
for (int j = 0, max = columnIndex + colspan; j < max; j++) {
for (int j = columnIndex, max = columnIndex + colspan; j < max; j++) {
if (row.getCell(j) == null) if (row.getCell(j) == null)
row.createCell(j); row.createCell(j);
} }
@@ -432,7 +432,6 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
for (int i = 0; i < colspan && i < columns.size(); i++) { for (int i = 0; i < colspan && i < columns.size(); i++) {
boolean isNumber = false; boolean isNumber = false;
params = columns.get(colspan * k + i); params = columns.get(colspan * k + i);
ci += i;
tempCreateCellSet.add(row.getRowNum() + "_" + (ci)); tempCreateCellSet.add(row.getRowNum() + "_" + (ci));
if (params == null) { if (params == null) {
continue; continue;
@@ -440,6 +439,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
if (StringUtils.isEmpty(params.getName()) if (StringUtils.isEmpty(params.getName())
&& StringUtils.isEmpty(params.getConstValue())) { && StringUtils.isEmpty(params.getConstValue())) {
row.getCell(ci).setCellStyle(columns.get(i).getCellStyle()); row.getCell(ci).setCellStyle(columns.get(i).getCellStyle());
ci = ci + columns.get(i).getColspan();
continue; continue;
} }
String val = null; String val = null;
@@ -459,7 +459,11 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
row.getCell(ci).setCellValue(Double.parseDouble(val)); row.getCell(ci).setCellValue(Double.parseDouble(val));
row.getCell(ci).setCellType(Cell.CELL_TYPE_NUMERIC); row.getCell(ci).setCellType(Cell.CELL_TYPE_NUMERIC);
} else { } else {
row.getCell(ci).setCellValue(val);
try {
row.getCell(ci).setCellValue(val);
} catch (Exception e) {
LOGGER.error(e.getMessage(),e);
}
} }
row.getCell(ci).setCellStyle(columns.get(i).getCellStyle()); row.getCell(ci).setCellStyle(columns.get(i).getCellStyle());
//如果合并单元格,就把这个单元格的样式和之前的保持一致 //如果合并单元格,就把这个单元格的样式和之前的保持一致
@@ -472,7 +476,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
row.getRowNum() + params.getRowspan() - 1, ci, row.getRowNum() + params.getRowspan() - 1, ci,
ci + params.getColspan() - 1)); ci + params.getColspan() - 1));
} }
ci = ci - i + columns.get(i).getColspan() - 1;
ci = ci + columns.get(i).getColspan();
} }
row = row.getSheet().getRow(row.getRowNum() + 1); row = row.getSheet().getRow(row.getRowNum() + 1);
} }
@@ -516,7 +520,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
int startIndex = cell.getColumnIndex(); int startIndex = cell.getColumnIndex();
Row row = cell.getRow(); Row row = cell.getRow();
while (true) { while (true) {
index += columns.get(columns.size() - 1).getColspan();
index += 1;
cell = row.getCell(index); cell = row.getCell(index);
//可能是合并的单元格 //可能是合并的单元格
if (cell == null) { if (cell == null) {
@@ -562,6 +566,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
for (int i = 0; i < columns.size(); i++) { for (int i = 0; i < columns.size(); i++) {
colspan += columns.get(i).getColspan(); colspan += columns.get(i).getColspan();
} }
colspan = colspan/rowspan;
return new Object[] { rowspan, colspan, columns }; return new Object[] { rowspan, colspan, columns };
} }


Loading…
取消
儲存