Bladeren bron

foreach 的styler 复制

4.1.3.A
jueyue 9 jaren geleden
bovenliggende
commit
ee02e63e97
4 gewijzigde bestanden met toevoegingen van 86 en 12 verwijderingen
  1. +2
    -2
      README.md
  2. +65
    -0
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelTemplateParams.java
  3. +19
    -10
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java
  4. BIN
      easypoi-test/src/main/java/org/jeecgframework/poi/test/excel/doc/foreach.xlsx

+ 2
- 2
README.md Bestand weergeven

@@ -143,8 +143,8 @@ EasyPoi 模板 表达式支持
- fn: 格式化数字 {{fn:(obj;###.00)}}
- fe: 遍历数据,创建row
- !fe: 遍历数据不创建row
- !if: 这一列是否加入,最好是第一个个有效行,删除可能营销其他数据 {{!if:(test)}}
- 单引号表示常量值 ''
- !if: 删除当前列 {{!if:(test)}}
- 单引号表示常量值 '' 比如'1' 那么输出的就是 1
---------------------------


+ 65
- 0
easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelTemplateParams.java Bestand weergeven

@@ -0,0 +1,65 @@
package org.jeecgframework.poi.excel.entity.params;
import java.io.Serializable;
import org.apache.poi.ss.usermodel.CellStyle;
/**
* 模板便利是的参数
* @author JueYue
* @date 2015年4月29日 下午9:22:48
*/
public class ExcelTemplateParams implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* key
*/
private String name;
/**
* 模板的cellStyle
*/
private CellStyle cellStyle;
/**
* 行高
*/
private short height;
public ExcelTemplateParams() {
}
public ExcelTemplateParams(String name, CellStyle cellStyle, short height) {
this.name = name;
this.cellStyle = cellStyle;
this.height = height;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CellStyle getCellStyle() {
return cellStyle;
}
public void setCellStyle(CellStyle cellStyle) {
this.cellStyle = cellStyle;
}
public short getHeight() {
return height;
}
public void setHeight(short height) {
this.height = height;
}
}

+ 19
- 10
easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java Bestand weergeven

@@ -38,6 +38,7 @@ import org.jeecgframework.poi.excel.annotation.ExcelTarget;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.excel.entity.params.ExcelTemplateParams;
import org.jeecgframework.poi.excel.export.base.ExcelExportBase;
import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler;
import org.jeecgframework.poi.exception.excel.ExcelExportException;
@@ -353,7 +354,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
.replace(START_STR, EMPTY);
String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" ");
Collection<?> datas = (Collection<?>) PoiPublicUtil.getParamsValue(keys[0], map);
List<String> columns = getAllDataColumns(cell, name.replace(keys[0], EMPTY));
List<ExcelTemplateParams> columns = getAllDataColumns(cell, name.replace(keys[0], EMPTY));
if (datas == null) {
return;
}
@@ -363,6 +364,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
//处理当前行
if (its.hasNext()) {
Object t = its.next();
cell.getRow().setHeight(columns.get(0).getHeight());
setForEeachCellValue(isCreate, cell.getRow(), cell.getColumnIndex(), t, columns, map);
}
while (its.hasNext()) {
@@ -375,20 +377,21 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
row = cell.getRow().getSheet().createRow(rowIndex - 1);
}
}
row.setHeight(columns.get(0).getHeight());
setForEeachCellValue(isCreate, row, cell.getColumnIndex(), t, columns, map);
}
}
private void setForEeachCellValue(boolean isCreate, Row row, int columnIndex, Object t,
List<String> columns, Map<String, Object> map)
throws Exception {
List<ExcelTemplateParams> columns, Map<String, Object> map)
throws Exception {
for (int i = 0, max = columnIndex + columns.size(); i < max; i++) {
if (row.getCell(i) == null)
row.createCell(i);
}
for (int i = 0, max = columns.size(); i < max; i++) {
boolean isNumber = false;
String tempStr = new String(columns.get(i));
String tempStr = new String(columns.get(i).getName());
if (isNumber(tempStr)) {
isNumber = true;
tempStr = tempStr.replace(NUMBER_SYMBOL, "");
@@ -398,8 +401,10 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
if (isNumber) {
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());
}
tempCreateCellSet.add(row.getRowNum() + "_" + (i + columnIndex));
}
@@ -412,14 +417,16 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
* @param name
* @return
*/
private List<String> getAllDataColumns(Cell cell, String name) {
List<String> columns = new ArrayList<String>();
private List<ExcelTemplateParams> getAllDataColumns(Cell cell, String name) {
List<ExcelTemplateParams> columns = new ArrayList<ExcelTemplateParams>();
if (name.contains(END_STR)) {
columns.add(name.replace(END_STR, EMPTY));
columns.add(new ExcelTemplateParams(name.replace(END_STR, EMPTY), cell.getCellStyle(),
cell.getRow().getHeight()));
cell.setCellValue("");
return columns;
}
columns.add(name.trim());
columns.add(new ExcelTemplateParams(name.trim(), cell.getCellStyle(), cell.getRow()
.getHeight()));
int index = cell.getColumnIndex();
Cell tempCell;
while (true) {
@@ -439,11 +446,13 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase {
//把读取过的cell 置为空
cell.setCellValue("");
if (cellStringString.contains(END_STR)) {
columns.add(cellStringString.trim().replace(END_STR, ""));
columns.add(new ExcelTemplateParams(cellStringString.trim().replace(END_STR, ""),
tempCell.getCellStyle(), tempCell.getRow().getHeight()));
break;
} else {
if (cellStringString.trim().contains(teplateParams.getTempParams())) {
columns.add(cellStringString.trim());
columns.add(new ExcelTemplateParams(cellStringString.trim(), tempCell
.getCellStyle(), tempCell.getRow().getHeight()));
} else {
//最后一行被删除了
break;


BIN
easypoi-test/src/main/java/org/jeecgframework/poi/test/excel/doc/foreach.xlsx Bestand weergeven


Laden…
Annuleren
Opslaan