Przeglądaj źródła

修复了几个bug,导入增加了一个忽略最后几行的参数,加入了$fe标签

4.1.3.A
jueyue 9 lat temu
rodzic
commit
9da06b5cd4
8 zmienionych plików z 34 dodań i 13 usunięć
  1. +1
    -0
      README.md
  2. +12
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/ImportParams.java
  3. +13
    -7
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java
  4. +2
    -1
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/ExcelImportServer.java
  5. +1
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiElUtil.java
  6. +4
    -4
      easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiFunctionUtil.java
  7. BIN
      easypoi-test/src/main/java/org/jeecgframework/poi/test/excel/doc/foreach.xlsx
  8. +1
    -1
      easypoi-test/src/main/java/org/jeecgframework/poi/test/excel/template/TemplateForEachTest.java

+ 1
- 0
README.md Wyświetl plik

@@ -143,6 +143,7 @@ EasyPoi 模板 表达式支持
- fn: 格式化数字 {{fn:(obj;###.00)}}
- fe: 遍历数据,创建row
- !fe: 遍历数据不创建row
- $fe: 下移插入,把当前行,下面的行全部下移.size()行,然后插入
- !if: 删除当前列 {{!if:(test)}}
- 单引号表示常量值 '' 比如'1' 那么输出的就是 1


+ 12
- 0
easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/ImportParams.java Wyświetl plik

@@ -58,6 +58,10 @@ public class ImportParams extends ExcelBaseParams {
* 校验处理接口
*/
private IExcelVerifyHandler verifyHanlder;
/**
* 最后的无效行数
*/
private int lastOfInvalidRow;
public int getHeadRows() {
return headRows;
@@ -123,4 +127,12 @@ public class ImportParams extends ExcelBaseParams {
this.verifyHanlder = verifyHanlder;
}
public int getLastOfInvalidRow() {
return lastOfInvalidRow;
}
public void setLastOfInvalidRow(int lastOfInvalidRow) {
this.lastOfInvalidRow = lastOfInvalidRow;
}
}

+ 13
- 7
easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java Wyświetl plik

@@ -350,8 +350,9 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
private void addListDataToExcel(Cell cell, Map<String, Object> map, String name)
throws Exception {
boolean isCreate = !name.contains(FOREACH_NOT_CREATE);
name = name.replace(FOREACH_NOT_CREATE, EMPTY).replace(FOREACH, EMPTY)
.replace(START_STR, EMPTY);
boolean isShift = name.contains(FOREACH_AND_SHIFT);
name = name.replace(FOREACH_NOT_CREATE, EMPTY).replace(FOREACH_AND_SHIFT, EMPTY)
.replace(FOREACH, EMPTY).replace(START_STR, EMPTY);
String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" ");
Collection<?> datas = (Collection<?>) PoiPublicUtil.getParamsValue(keys[0], map);
List<ExcelTemplateParams> columns = getAllDataColumns(cell, name.replace(keys[0], EMPTY));
@@ -367,6 +368,12 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
cell.getRow().setHeight(columns.get(0).getHeight());
setForEeachCellValue(isCreate, cell.getRow(), cell.getColumnIndex(), t, columns, map);
}
if (isShift) {
cell.getRow()
.getSheet()
.shiftRows(cell.getRowIndex() + 1, cell.getRow().getSheet().getLastRowNum(),
datas.size() - 1, true, true);
}
while (its.hasNext()) {
Object t = its.next();
if (isCreate) {
@@ -398,14 +405,13 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
}
map.put(teplateParams.getTempParams(), t);
String val = eval(tempStr, map).toString();
if (isNumber) {
if (isNumber && StringUtils.isNoneEmpty(val)) {
row.getCell(i + columnIndex).setCellValue(Double.parseDouble(val));
row.getCell(i + columnIndex).setCellType(Cell.CELL_TYPE_NUMERIC);
row.getCell(i + columnIndex).setCellStyle(columns.get(i).getCellStyle());
} else {
row.getCell(i + columnIndex).setCellValue(val);
row.getCell(i + columnIndex).setCellStyle(columns.get(i).getCellStyle());
}
row.getCell(i + columnIndex).setCellStyle(columns.get(i).getCellStyle());
tempCreateCellSet.add(row.getRowNum() + "_" + (i + columnIndex));
}
@@ -419,10 +425,10 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
*/
private List<ExcelTemplateParams> getAllDataColumns(Cell cell, String name) {
List<ExcelTemplateParams> columns = new ArrayList<ExcelTemplateParams>();
cell.setCellValue("");
if (name.contains(END_STR)) {
columns.add(new ExcelTemplateParams(name.replace(END_STR, EMPTY).trim(), cell
.getCellStyle(), cell.getRow().getHeight()));
cell.setCellValue("");
return columns;
}
columns.add(new ExcelTemplateParams(name.trim(), cell.getCellStyle(), cell.getRow()
@@ -444,7 +450,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
throw new ExcelExportException("for each 当中存在空字符串,请检查模板");
}
//把读取过的cell 置为空
cell.setCellValue("");
tempCell.setCellValue("");
if (cellStringString.contains(END_STR)) {
columns.add(new ExcelTemplateParams(cellStringString.trim().replace(END_STR, ""),
tempCell.getCellStyle(), tempCell.getRow().getHeight()));


+ 2
- 1
easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/ExcelImportServer.java Wyświetl plik

@@ -191,7 +191,8 @@ public class ExcelImportServer extends ImportBaseService {
Row row = null;
Object object = null;
String picId;
while (rows.hasNext()) {
while (rows.hasNext()
&& sheet.getLastRowNum() - row.getRowNum() > params.getLastOfInvalidRow()) {
row = rows.next();
// 判断是集合元素还是不是集合元素,如果是就继续加入这个集合,不是就创建新的对象
if ((row.getCell(params.getKeyIndex()) == null || StringUtils.isEmpty(getKeyValue(row


+ 1
- 0
easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiElUtil.java Wyświetl plik

@@ -29,6 +29,7 @@ public final class PoiElUtil {
public static final String LENGTH = "le:";
public static final String FOREACH = "fe:";
public static final String FOREACH_NOT_CREATE = "!fe:";
public static final String FOREACH_AND_SHIFT = "$fe:";
public static final String START_STR = "{{";
public static final String END_STR = "}}";
public static final String NUMBER_SYMBOL = "n:";


+ 4
- 4
easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiFunctionUtil.java Wyświetl plik

@@ -98,7 +98,7 @@ public final class PoiFunctionUtil {
* @return
*/
public static String formatDate(Object obj, String format) {
if (obj == null) {
if (obj == null || obj.toString() == "") {
return "";
}
SimpleDateFormat dateFormat = null;
@@ -148,11 +148,11 @@ public final class PoiFunctionUtil {
* @return
*/
private static boolean isGt(Object first, Object second) {
if (first == null) {
if (first == null || first.toString() == "") {
return false;
}
if (second == null) {
return false;
if (second == null || second.toString() == "") {
return true;
}
double one = Double.valueOf(first.toString());
double two = Double.valueOf(second.toString());


BIN
easypoi-test/src/main/java/org/jeecgframework/poi/test/excel/doc/foreach.xlsx Wyświetl plik


+ 1
- 1
easypoi-test/src/main/java/org/jeecgframework/poi/test/excel/template/TemplateForEachTest.java Wyświetl plik

@@ -40,7 +40,7 @@ public class TemplateForEachTest {
map.put("entitylist", list);
map.put("letest", "12345678");
map.put("fntest", "12345678.2341234");
map.put("fdtest", new Date());
map.put("fdtest", null);
List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 4; i++) {
Map<String, Object> testMap = new HashMap<String, Object>();


Ładowanie…
Anuluj
Zapisz