Ver a proveniência

加入,fe的图片支持

4.1.3.A
jueyue há 7 anos
ascendente
cometimento
4fc315d38b
3 ficheiros alterados com 65 adições e 33 eliminações
  1. +19
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/entity/ImageEntity.java
  2. +18
    -5
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java
  3. +28
    -28
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiElUtil.java

+ 19
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/entity/ImageEntity.java Ver ficheiro

@@ -41,6 +41,10 @@ public class ImageEntity {
// 图片信息
private byte[] data;

private int rowspan = 1;
private int colspan = 1;


public ImageEntity() {

}
@@ -98,4 +102,19 @@ public class ImageEntity {
this.width = width;
}

public int getRowspan() {
return rowspan;
}

public void setRowspan(int rowspan) {
this.rowspan = rowspan;
}

public int getColspan() {
return colspan;
}

public void setColspan(int colspan) {
this.colspan = colspan;
}
}

+ 18
- 5
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java Ver ficheiro

@@ -407,10 +407,15 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
oldString = oldString.replaceFirst(NUMBER_SYMBOL, "");
}
Object obj = PoiPublicUtil.getRealValue(oldString, map);
//如何是数值 类型,就按照数值类型进行设置
if (obj instanceof ImageEntity) {// 如果是图片就设置为图片
//如何是数值 类型,就按照数值类型进行设置// 如果是图片就设置为图片
if (obj instanceof ImageEntity) {
ImageEntity img = (ImageEntity)obj;
cell.setCellValue("");
if (img.getRowspan()>1 || img.getColspan() > 1){
img.setHeight(0);
cell.getSheet().addMergedRegion(new CellRangeAddress(cell.getRowIndex(),
cell.getRowIndex() + img.getRowspan() - 1, cell.getColumnIndex(), cell.getColumnIndex() + img.getColspan() -1));
}
createImageCell(cell,img.getHeight(),img.getUrl(),img.getData());
}else if (isNumber && StringUtils.isNotBlank(obj.toString())) {
cell.setCellValue(Double.parseDouble(obj.toString()));
@@ -464,7 +469,9 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
rowspan, colspan, mergedRegionHelper);
rowIndex += rowspan - 1;
}
if (isShift && datas.size() * rowspan > 1 && cell.getRowIndex() + rowspan < cell.getRow().getSheet().getLastRowNum()) {
//不论后面有没有数据,都应该执行的是插入操作
// && cell.getRowIndex() + rowspan < cell.getRow().getSheet().getLastRowNum()
if (isShift && datas.size() * rowspan > 1) {
createRowNoRow(cell.getRowIndex() + rowspan,cell.getRow().getSheet().getLastRowNum(),(datas.size() - 1) * rowspan);
cell.getRow().getSheet().shiftRows(cell.getRowIndex() + rowspan,
cell.getRow().getSheet().getLastRowNum(), (datas.size() - 1) * rowspan, true, true);
@@ -548,6 +555,7 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
continue;
}
String val = null;
Object obj = null;
//是不是常量
if (StringUtils.isEmpty(params.getName())) {
val = params.getConstValue();
@@ -558,9 +566,14 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
tempStr = tempStr.replaceFirst(NUMBER_SYMBOL, "");
}
map.put(teplateParams.getTempParams(), t);
val = eval(tempStr, map).toString();
obj = eval(tempStr, map);
val = obj.toString();
}
if (isNumber && StringUtils.isNotEmpty(val)) {
if (obj != null && obj instanceof ImageEntity) {
ImageEntity img = (ImageEntity)obj;
row.getCell(ci).setCellValue("");
createImageCell(row.getCell(ci),img.getHeight(),img.getUrl(),img.getData());
}else if (isNumber && StringUtils.isNotEmpty(val)) {
row.getCell(ci).setCellValue(Double.parseDouble(val));
row.getCell(ci).setCellType(Cell.CELL_TYPE_NUMERIC);
} else {


+ 28
- 28
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiElUtil.java Ver ficheiro

@@ -1,6 +1,6 @@
/**
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -26,25 +26,25 @@ import cn.afterturn.easypoi.exception.excel.ExcelExportException;
*/
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 FOREACH_COL = "#fe:";
public static final String FOREACH_COL_VALUE = "v_fe:";
public static final String START_STR = "{{";
public static final String END_STR = "}}";
public static final String WRAP = "]]";
public static final String NUMBER_SYMBOL = "n:";
public static final String FORMAT_DATE = "fd:";
public static final String FORMAT_NUMBER = "fn:";
public static final String SUM = "sum:";
public static final String IF_DELETE = "!if:";
public static final String EMPTY = "";
public static final String CONST = "'";
public static final String NULL = "&NULL&";
public static final String LEFT_BRACKET = "(";
public static final String RIGHT_BRACKET = ")";
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 FOREACH_COL = "#fe:";
public static final String FOREACH_COL_VALUE = "v_fe:";
public static final String START_STR = "{{";
public static final String END_STR = "}}";
public static final String WRAP = "]]";
public static final String NUMBER_SYMBOL = "n:";
public static final String FORMAT_DATE = "fd:";
public static final String FORMAT_NUMBER = "fn:";
public static final String SUM = "sum:";
public static final String IF_DELETE = "!if:";
public static final String EMPTY = "";
public static final String CONST = "'";
public static final String NULL = "&NULL&";
public static final String LEFT_BRACKET = "(";
public static final String RIGHT_BRACKET = ")";
private PoiElUtil() {
}
@@ -54,7 +54,7 @@ public final class PoiElUtil {
* @param text
* @param map
* @return
* @throws Exception
* @throws Exception
*/
public static Object eval(String text, Map<String, Object> map) throws Exception {
String tempText = new String(text);
@@ -71,7 +71,7 @@ public final class PoiElUtil {
* @param text
* @param map
* @return
* @throws Exception
* @throws Exception
*/
public static Object innerEval(String text, Map<String, Object> map) throws Exception {
if (text.indexOf("?") != -1 && text.indexOf(":") != -1) {
@@ -100,7 +100,7 @@ public final class PoiElUtil {
* @param text
* @param map
* @return
* @throws Exception
* @throws Exception
*/
private static Object ifDelete(String text, Map<String, Object> map) throws Exception {
//把多个空格变成一个空格
@@ -150,7 +150,7 @@ public final class PoiElUtil {
* @param text
* @param map
* @return
* @throws Exception
* @throws Exception
*/
private static Object formatNumber(String text, Map<String, Object> map) throws Exception {
String[] key = getKey(FORMAT_NUMBER, text).split(";");
@@ -166,7 +166,7 @@ public final class PoiElUtil {
* @param text
* @param map
* @return
* @throws Exception
* @throws Exception
*/
private static Object formatDate(String text, Map<String, Object> map) throws Exception {
String[] key = getKey(FORMAT_DATE, text).split(";");
@@ -181,7 +181,7 @@ public final class PoiElUtil {
* 计算这个的长度
* @param text
* @param map
* @throws Exception
* @throws Exception
*/
private static Object length(String text, Map<String, Object> map) throws Exception {
String key = getKey(LENGTH, text);
@@ -226,7 +226,7 @@ public final class PoiElUtil {
/**
* 三目运算
* @return
* @throws Exception
* @throws Exception
*/
private static Object trinocular(String text, Map<String, Object> map) throws Exception {
//把多个空格变成一个空格
@@ -250,7 +250,7 @@ public final class PoiElUtil {
for (int i = 2; i < keys.length; i++) {
trinocular += ":" + keys[i];
}
second = eval(trinocular, map);
second = eval(trinocular, map);
}
}else{
first = eval(keys[0].trim(), map);


Carregando…
Cancelar
Guardar