@@ -41,7 +41,7 @@ public @interface ExcelEntity { | |||
public String name() default ""; | |||
/** | |||
* 如果现实则这个Excel的表头会变成两行,同时改Excel内部数据不参与总排序,排序用下面这个来代替,内部再排序 | |||
* 如果等于true,name必须有值, Excel的表头会变成两行,同时改Excel内部数据不参与总排序,排序用下面这个来代替,内部再排序 | |||
* @return | |||
*/ | |||
public boolean show() default false; | |||
@@ -19,6 +19,7 @@ import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; | |||
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; | |||
import cn.afterturn.easypoi.exception.excel.ExcelExportException; | |||
import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; | |||
import cn.afterturn.easypoi.util.PoiExcelGraphDataUtil; | |||
import cn.afterturn.easypoi.util.PoiPublicUtil; | |||
/** | |||
@@ -115,7 +116,7 @@ public class ExcelBatchExportServer extends ExcelExportServer { | |||
// 创建表格样式 | |||
setExcelExportStyler((IExcelExportStyler) entity.getStyle() | |||
.getConstructor(Workbook.class).newInstance(workbook)); | |||
patriarch = sheet.createDrawingPatriarch(); | |||
patriarch = PoiExcelGraphDataUtil.getDrawingPatriarch(sheet); | |||
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | |||
if (entity.isAddIndex()) { | |||
excelParams.add(indexExcelEntity(entity)); | |||
@@ -38,6 +38,7 @@ import cn.afterturn.easypoi.excel.export.base.ExcelExportBase; | |||
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; | |||
import cn.afterturn.easypoi.exception.excel.ExcelExportException; | |||
import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; | |||
import cn.afterturn.easypoi.util.PoiExcelGraphDataUtil; | |||
import cn.afterturn.easypoi.util.PoiPublicUtil; | |||
/** | |||
@@ -161,7 +162,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||
// 创建表格样式 | |||
setExcelExportStyler((IExcelExportStyler) entity.getStyle() | |||
.getConstructor(Workbook.class).newInstance(workbook)); | |||
Drawing patriarch = sheet.createDrawingPatriarch(); | |||
Drawing patriarch = PoiExcelGraphDataUtil.getDrawingPatriarch(sheet); | |||
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | |||
if (entity.isAddIndex()) { | |||
excelParams.add(indexExcelEntity(entity)); | |||
@@ -1,27 +1,18 @@ | |||
/** | |||
* 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 | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software distributed under the License | |||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |||
* or implied. See the License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package cn.afterturn.easypoi.excel.export.base; | |||
import java.text.DecimalFormat; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | |||
import org.apache.poi.hssf.usermodel.HSSFRichTextString; | |||
@@ -37,45 +28,43 @@ import org.apache.poi.ss.util.CellRangeAddress; | |||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | |||
import org.apache.poi.xssf.usermodel.XSSFRichTextString; | |||
import java.text.DecimalFormat; | |||
import java.util.Collection; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import cn.afterturn.easypoi.cache.ImageCache; | |||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; | |||
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; | |||
import cn.afterturn.easypoi.excel.entity.vo.BaseEntityTypeConstants; | |||
import cn.afterturn.easypoi.excel.entity.vo.PoiBaseConstants; | |||
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler; | |||
import cn.afterturn.easypoi.util.PoiExcelGraphDataUtil; | |||
import cn.afterturn.easypoi.util.PoiMergeCellUtil; | |||
import cn.afterturn.easypoi.util.PoiPublicUtil; | |||
/** | |||
* 提供POI基础操作服务 | |||
* | |||
* @author JueYue | |||
* 2014年6月17日 下午6:15:13 | |||
* | |||
* @author JueYue 2014年6月17日 下午6:15:13 | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
public abstract class ExcelExportBase extends ExportBase { | |||
private int currentIndex = 0; | |||
private int currentIndex = 0; | |||
protected ExcelType type = ExcelType.HSSF; | |||
protected ExcelType type = ExcelType.HSSF; | |||
private Map<Integer, Double> statistics = new HashMap<Integer, Double>(); | |||
private Map<Integer, Double> statistics = new HashMap<Integer, Double>(); | |||
private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); | |||
protected IExcelExportStyler excelExportStyler; | |||
protected IExcelExportStyler excelExportStyler; | |||
/** | |||
* 创建 最主要的 Cells | |||
* @param patriarch | |||
* @param index | |||
* @param t | |||
* @param excelParams | |||
* @param sheet | |||
* @param workbook | |||
* @param rowHeight | |||
* @return | |||
* @throws Exception | |||
*/ | |||
public int createCells(Drawing patriarch, int index, Object t, | |||
List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook, | |||
@@ -94,7 +83,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||
if (list != null && list.size() > 0) { | |||
for (Object obj : list) { | |||
createListCells(patriarch, index + listC, cellNum, obj, entity.getList(), | |||
sheet, workbook); | |||
sheet, workbook); | |||
listC++; | |||
} | |||
} | |||
@@ -103,31 +92,31 @@ public abstract class ExcelExportBase extends ExportBase { | |||
maxHeight = list.size(); | |||
} | |||
} else { | |||
Object value = getCellValue(entity, t); | |||
Object value = getCellValue(entity, t); | |||
if (entity.getType() == BaseEntityTypeConstants.StringType) { | |||
createStringCell(row, cellNum++, value == null ? "" : value.toString(), | |||
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), | |||
entity); | |||
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), | |||
entity); | |||
if (entity.isHyperlink()) { | |||
row.getCell(cellNum - 1) | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), t, | |||
entity.getName(), value)); | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), t, | |||
entity.getName(), value)); | |||
} | |||
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) { | |||
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), | |||
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), | |||
entity); | |||
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), | |||
entity); | |||
if (entity.isHyperlink()) { | |||
row.getCell(cellNum - 1) | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), t, | |||
entity.getName(), value)); | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), t, | |||
entity.getName(), value)); | |||
} | |||
} else { | |||
createImageCell(patriarch, entity, row, cellNum++, | |||
value == null ? "" : value.toString(), t); | |||
value == null ? "" : value.toString(), t); | |||
} | |||
} | |||
} | |||
@@ -143,7 +132,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||
sheet.getRow(i).getCell(cellNum).setCellStyle(getStyles(false, entity)); | |||
} | |||
sheet.addMergedRegion( | |||
new CellRangeAddress(index, index + maxHeight - 1, cellNum, cellNum)); | |||
new CellRangeAddress(index, index + maxHeight - 1, cellNum, cellNum)); | |||
cellNum++; | |||
} | |||
} | |||
@@ -153,50 +142,52 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 图片类型的Cell | |||
* | |||
* @param patriarch | |||
* @param entity | |||
* @param row | |||
* @param i | |||
* @param imagePath | |||
* @param obj | |||
* @throws Exception | |||
*/ | |||
public void createImageCell(Drawing patriarch, ExcelExportEntity entity, Row row, int i, | |||
String imagePath, Object obj) throws Exception { | |||
row.setHeight((short) (50 * entity.getHeight())); | |||
row.createCell(i); | |||
Cell cell = row.createCell(i); | |||
byte[] value = null; | |||
if (entity.getExportImageType() != 1) { | |||
value = (byte[]) (entity.getMethods() != null | |||
? getFieldBySomeMethod(entity.getMethods(), obj) | |||
: entity.getMethod().invoke(obj, new Object[]{})); | |||
} | |||
createImageCell(cell, 50 * entity.getHeight(), entity.getExportImageType() == 1 ? imagePath : null, value); | |||
} | |||
/** | |||
* 图片类型的Cell | |||
*/ | |||
public void createImageCell(Cell cell, double height, | |||
String imagePath, byte[] data) throws Exception { | |||
if (height > cell.getRow().getHeight()) { | |||
cell.getRow().setHeight((short) height); | |||
} | |||
ClientAnchor anchor; | |||
if (type.equals(ExcelType.HSSF)) { | |||
anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), | |||
row.getRowNum() + 1); | |||
anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), | |||
cell.getRow().getRowNum() + 1); | |||
} else { | |||
anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) i, row.getRowNum(), (short) (i + 1), | |||
row.getRowNum() + 1); | |||
anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1), | |||
cell.getRow().getRowNum() + 1); | |||
} | |||
byte[] value = null; | |||
if (entity.getExportImageType() == 1) { | |||
if (StringUtils.isNotEmpty(imagePath)) { | |||
value = ImageCache.getImage(imagePath); | |||
} | |||
} else { | |||
value = (byte[]) (entity.getMethods() != null | |||
? getFieldBySomeMethod(entity.getMethods(), obj) | |||
: entity.getMethod().invoke(obj, new Object[] {})); | |||
if (StringUtils.isNotEmpty(imagePath)) { | |||
data = ImageCache.getImage(imagePath); | |||
} | |||
if (value != null) { | |||
patriarch.createPicture(anchor, | |||
row.getSheet().getWorkbook().addPicture(value, getImageType(value))); | |||
if (data != null) { | |||
PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture(anchor, | |||
cell.getSheet().getWorkbook().addPicture(data, getImageType(data))); | |||
} | |||
} | |||
private int createIndexCell(Row row, int index, ExcelExportEntity excelExportEntity) { | |||
if (excelExportEntity.getName()!=null&&excelExportEntity.getName().equals("序号") && excelExportEntity.getFormat() != null | |||
&& excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) { | |||
if (excelExportEntity.getName() != null && excelExportEntity.getName().equals("序号") && excelExportEntity.getFormat() != null | |||
&& excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) { | |||
createStringCell(row, 0, currentIndex + "", | |||
index % 2 == 0 ? getStyles(false, null) : getStyles(true, null), null); | |||
index % 2 == 0 ? getStyles(false, null) : getStyles(true, null), null); | |||
currentIndex = currentIndex + 1; | |||
return 1; | |||
} | |||
@@ -205,14 +196,6 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 创建List之后的各个Cells | |||
* @param patriarch | |||
* @param index | |||
* @param cellNum | |||
* @param obj | |||
* @param excelParams | |||
* @param sheet | |||
* @param workbook | |||
* @throws Exception | |||
*/ | |||
public void createListCells(Drawing patriarch, int index, int cellNum, Object obj, | |||
List<ExcelExportEntity> excelParams, Sheet sheet, | |||
@@ -230,38 +213,32 @@ public abstract class ExcelExportBase extends ExportBase { | |||
Object value = getCellValue(entity, obj); | |||
if (entity.getType() == BaseEntityTypeConstants.StringType) { | |||
createStringCell(row, cellNum++, value == null ? "" : value.toString(), | |||
row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), | |||
entity); | |||
row.getRowNum() % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), | |||
entity); | |||
if (entity.isHyperlink()) { | |||
row.getCell(cellNum - 1) | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), | |||
value)); | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), | |||
value)); | |||
} | |||
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) { | |||
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), | |||
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity); | |||
index % 2 == 0 ? getStyles(false, entity) : getStyles(true, entity), entity); | |||
if (entity.isHyperlink()) { | |||
row.getCell(cellNum - 1) | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), | |||
value)); | |||
.setHyperlink(dataHanlder.getHyperlink( | |||
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), | |||
value)); | |||
} | |||
} else { | |||
createImageCell(patriarch, entity, row, cellNum++, | |||
value == null ? "" : value.toString(), obj); | |||
value == null ? "" : value.toString(), obj); | |||
} | |||
} | |||
} | |||
/** | |||
* 创建文本类型的Cell | |||
* | |||
* @param row | |||
* @param index | |||
* @param text | |||
* @param style | |||
* @param entity | |||
*/ | |||
public void createStringCell(Row row, int index, String text, CellStyle style, | |||
ExcelExportEntity entity) { | |||
@@ -286,12 +263,6 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 创建数字类型的Cell | |||
* | |||
* @param row | |||
* @param index | |||
* @param text | |||
* @param style | |||
* @param entity | |||
*/ | |||
public void createDoubleCell(Row row, int index, String text, CellStyle style, | |||
ExcelExportEntity entity) { | |||
@@ -308,8 +279,6 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 创建统计行 | |||
* @param styles | |||
* @param sheet | |||
*/ | |||
public void addStatisticsRow(CellStyle styles, Sheet sheet) { | |||
if (statistics.size() > 0) { | |||
@@ -326,9 +295,6 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 合计统计信息 | |||
* @param index | |||
* @param text | |||
* @param entity | |||
*/ | |||
private void addStatisticsData(Integer index, String text, ExcelExportEntity entity) { | |||
if (entity != null && entity.isStatistics()) { | |||
@@ -346,11 +312,8 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 获取图片类型,设置图片插入类型 | |||
* | |||
* @param value | |||
* @return | |||
* @author JueYue | |||
* 2013年11月25日 | |||
* | |||
* @author JueYue 2013年11月25日 | |||
*/ | |||
public int getImageType(byte[] value) { | |||
String type = PoiPublicUtil.getFileExtendName(value); | |||
@@ -359,7 +322,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||
} else if (type.equalsIgnoreCase("PNG")) { | |||
return Workbook.PICTURE_TYPE_PNG; | |||
} | |||
return Workbook.PICTURE_TYPE_JPEG; | |||
} | |||
@@ -387,9 +350,6 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 获取样式 | |||
* @param entity | |||
* @param needOne | |||
* @return | |||
*/ | |||
public CellStyle getStyles(boolean needOne, ExcelExportEntity entity) { | |||
return excelExportStyler.getStyles(needOne, entity); | |||
@@ -397,10 +357,6 @@ public abstract class ExcelExportBase extends ExportBase { | |||
/** | |||
* 合并单元格 | |||
* | |||
* @param sheet | |||
* @param excelParams | |||
* @param titleHeight | |||
*/ | |||
public void mergeCells(Sheet sheet, List<ExcelExportEntity> excelParams, int titleHeight) { | |||
Map<Integer, int[]> mergeMap = getMergeDataMap(excelParams); | |||
@@ -41,6 +41,7 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import cn.afterturn.easypoi.cache.ExcelCache; | |||
import cn.afterturn.easypoi.entity.ImageEntity; | |||
import cn.afterturn.easypoi.excel.annotation.ExcelTarget; | |||
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; | |||
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; | |||
@@ -52,6 +53,7 @@ import cn.afterturn.easypoi.excel.export.template.TemplateSumHanlder.TemplateSum | |||
import cn.afterturn.easypoi.excel.html.helper.MergedRegionHelper; | |||
import cn.afterturn.easypoi.exception.excel.ExcelExportException; | |||
import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; | |||
import cn.afterturn.easypoi.util.PoiExcelGraphDataUtil; | |||
import cn.afterturn.easypoi.util.PoiPublicUtil; | |||
import cn.afterturn.easypoi.util.PoiSheetUtility; | |||
@@ -98,7 +100,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
} | |||
// 获取表头数据 | |||
Map<String, Integer> titlemap = getTitleMap(sheet); | |||
Drawing patriarch = sheet.createDrawingPatriarch(); | |||
Drawing patriarch = PoiExcelGraphDataUtil.getDrawingPatriarch(sheet); | |||
// 得到所有字段 | |||
Field[] fileds = PoiPublicUtil.getClassFields(pojoClass); | |||
ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); | |||
@@ -400,19 +402,17 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
isNumber = true; | |||
oldString = oldString.replaceFirst(NUMBER_SYMBOL, ""); | |||
} | |||
while (oldString.indexOf(START_STR) != -1) { | |||
params = oldString.substring(oldString.indexOf(START_STR) + 2, | |||
oldString.indexOf(END_STR)); | |||
oldString = oldString.replace(START_STR + params + END_STR, | |||
eval(params, map).toString()); | |||
} | |||
Object obj = PoiPublicUtil.getRealValue(oldString, map); | |||
//如何是数值 类型,就按照数值类型进行设置 | |||
if (isNumber && StringUtils.isNotBlank(oldString)) { | |||
cell.setCellValue(Double.parseDouble(oldString)); | |||
if (obj instanceof ImageEntity) {// 如果是图片就设置为图片 | |||
ImageEntity img = (ImageEntity)obj; | |||
cell.setCellValue(""); | |||
createImageCell(cell,img.getHeight(),img.getUrl(),img.getData()); | |||
}else if (isNumber && StringUtils.isNotBlank(obj.toString())) { | |||
cell.setCellValue(Double.parseDouble(obj.toString())); | |||
cell.setCellType(Cell.CELL_TYPE_NUMERIC); | |||
} else { | |||
cell.setCellValue(oldString); | |||
cell.setCellValue(obj.toString()); | |||
} | |||
} | |||
//判断foreach 这种方法 | |||
@@ -135,7 +135,7 @@ public class ExcelChartBuildService | |||
{ | |||
int drawStart=0; | |||
int drawEnd=20; | |||
Drawing drawing = tragetSheet.createDrawingPatriarch(); | |||
Drawing drawing = PoiExcelGraphDataUtil.getDrawingPatriarch(tragetSheet); | |||
for(int i=0;i<len;i++){ | |||
ExcelGraph graph=graphList.get(i); | |||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, drawStart, 15, drawEnd); | |||
@@ -151,13 +151,12 @@ public class ExcelChartBuildService | |||
/** | |||
* 构建图形对象 | |||
* @param workbook | |||
* @param dataSourceSheet | |||
* @param tragetSheet | |||
* @param graph | |||
*/ | |||
private static void buildExcelChart(Sheet dataSourceSheet,Sheet tragetSheet,ExcelGraph graph){ | |||
Drawing drawing = tragetSheet.createDrawingPatriarch(); | |||
Drawing drawing = PoiExcelGraphDataUtil.getDrawingPatriarch(tragetSheet); | |||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 0, 15, 20); | |||
buildExcelChart(drawing, anchor, dataSourceSheet, graph); | |||
} | |||
@@ -5,6 +5,7 @@ package cn.afterturn.easypoi.util; | |||
import java.util.List; | |||
import org.apache.poi.ss.usermodel.Drawing; | |||
import org.apache.poi.ss.usermodel.Sheet; | |||
import cn.afterturn.easypoi.excel.graph.entity.ExcelGraph; | |||
@@ -48,4 +49,16 @@ public class PoiExcelGraphDataUtil { | |||
} | |||
} | |||
/** | |||
* 获取画布,没有就创建一个 | |||
* @param sheet | |||
* @return | |||
*/ | |||
public static Drawing getDrawingPatriarch(Sheet sheet){ | |||
if(sheet.getDrawingPatriarch() == null){ | |||
sheet.createDrawingPatriarch(); | |||
} | |||
return sheet.getDrawingPatriarch(); | |||
} | |||
} |
@@ -52,11 +52,12 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import cn.afterturn.easypoi.cache.ImageCache; | |||
import cn.afterturn.easypoi.excel.annotation.Excel; | |||
import cn.afterturn.easypoi.excel.annotation.ExcelCollection; | |||
import cn.afterturn.easypoi.excel.annotation.ExcelEntity; | |||
import cn.afterturn.easypoi.excel.annotation.ExcelIgnore; | |||
import cn.afterturn.easypoi.word.entity.WordImageEntity; | |||
import cn.afterturn.easypoi.entity.ImageEntity; | |||
import cn.afterturn.easypoi.word.entity.params.ExcelListEntity; | |||
/** | |||
@@ -326,20 +327,11 @@ public final class PoiPublicUtil { | |||
*@return (byte[]) isAndType[0],(Integer)isAndType[1] | |||
* @throws Exception | |||
*/ | |||
public static Object[] getIsAndType(WordImageEntity entity) throws Exception { | |||
public static Object[] getIsAndType(ImageEntity entity) throws Exception { | |||
Object[] result = new Object[2]; | |||
String type; | |||
if (entity.getType().equals(WordImageEntity.URL)) { | |||
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); | |||
BufferedImage bufferImg; | |||
String path = Thread.currentThread().getContextClassLoader().getResource("").toURI() | |||
.getPath() + entity.getUrl(); | |||
path = path.replace("WEB-INF/classes/", ""); | |||
path = path.replace("file:/", ""); | |||
bufferImg = ImageIO.read(new File(path)); | |||
ImageIO.write(bufferImg, entity.getUrl().substring(entity.getUrl().indexOf(".") + 1, | |||
entity.getUrl().length()), byteArrayOut); | |||
result[0] = byteArrayOut.toByteArray(); | |||
if (entity.getType().equals(ImageEntity.URL)) { | |||
result[0] = ImageCache.getImage(entity.getUrl()); | |||
type = entity.getUrl().split("/.")[entity.getUrl().split("/.").length - 1]; | |||
} else { | |||
result[0] = entity.getData(); | |||
@@ -383,8 +375,7 @@ public final class PoiPublicUtil { | |||
currentText.indexOf(END_STR)); | |||
Object obj = PoiElUtil.eval(params.trim(), map); | |||
//判断图片或者是集合 | |||
if (obj instanceof WordImageEntity || obj instanceof List | |||
if (obj instanceof ImageEntity || obj instanceof List | |||
|| obj instanceof ExcelListEntity) { | |||
return obj; | |||
} else { | |||
@@ -409,7 +400,7 @@ public final class PoiPublicUtil { | |||
if (object == null) { | |||
return ""; | |||
} | |||
if (object instanceof WordImageEntity) { | |||
if (object instanceof ImageEntity) { | |||
return object; | |||
} | |||
if (object instanceof Map) { | |||
@@ -1,101 +1,40 @@ | |||
/** | |||
* 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 | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* 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 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software distributed under the License | |||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |||
* or implied. See the License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package cn.afterturn.easypoi.word.entity; | |||
import cn.afterturn.easypoi.entity.ImageEntity; | |||
/** | |||
* word导出,图片设置和图片信息 | |||
* | |||
* | |||
* @author JueYue | |||
* 2013-11-17 | |||
* @version 1.0 | |||
*/ | |||
public class WordImageEntity { | |||
public static String URL = "url"; | |||
public static String Data = "data"; | |||
/** | |||
* 图片输入方式 | |||
*/ | |||
private String type = URL; | |||
/** | |||
* 图片宽度 | |||
*/ | |||
private int width; | |||
// 图片高度 | |||
private int height; | |||
// 图片地址 | |||
private String url; | |||
// 图片信息 | |||
private byte[] data; | |||
@Deprecated | |||
public class WordImageEntity extends ImageEntity { | |||
public WordImageEntity() { | |||
} | |||
public WordImageEntity(byte[] data, int width, int height) { | |||
this.data = data; | |||
this.width = width; | |||
this.height = height; | |||
this.type = Data; | |||
super(data, width, height); | |||
} | |||
public WordImageEntity(String url, int width, int height) { | |||
this.url = url; | |||
this.width = width; | |||
this.height = height; | |||
} | |||
public byte[] getData() { | |||
return data; | |||
} | |||
public int getHeight() { | |||
return height; | |||
} | |||
public String getType() { | |||
return type; | |||
} | |||
public String getUrl() { | |||
return url; | |||
} | |||
public int getWidth() { | |||
return width; | |||
} | |||
public void setData(byte[] data) { | |||
this.data = data; | |||
} | |||
public void setHeight(int height) { | |||
this.height = height; | |||
} | |||
public void setType(String type) { | |||
this.type = type; | |||
} | |||
public void setUrl(String url) { | |||
this.url = url; | |||
} | |||
public void setWidth(int width) { | |||
this.width = width; | |||
super(url, width, height); | |||
} | |||
} |
@@ -35,9 +35,9 @@ import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import cn.afterturn.easypoi.cache.WordCache; | |||
import cn.afterturn.easypoi.entity.ImageEntity; | |||
import cn.afterturn.easypoi.util.PoiPublicUtil; | |||
import cn.afterturn.easypoi.word.entity.MyXWPFDocument; | |||
import cn.afterturn.easypoi.word.entity.WordImageEntity; | |||
import cn.afterturn.easypoi.word.entity.params.ExcelListEntity; | |||
import cn.afterturn.easypoi.word.parse.excel.ExcelEntityParse; | |||
import cn.afterturn.easypoi.word.parse.excel.ExcelMapParse; | |||
@@ -63,7 +63,7 @@ public class ParseWord07 { | |||
* @param currentRun | |||
* @throws Exception | |||
*/ | |||
private void addAnImage(WordImageEntity obj, XWPFRun currentRun) throws Exception { | |||
private void addAnImage(ImageEntity obj, XWPFRun currentRun) throws Exception { | |||
Object[] isAndType = PoiPublicUtil.getIsAndType(obj); | |||
String picId; | |||
try { | |||
@@ -90,9 +90,9 @@ public class ParseWord07 { | |||
private void changeValues(XWPFParagraph paragraph, XWPFRun currentRun, String currentText, | |||
List<Integer> runIndex, Map<String, Object> map) throws Exception { | |||
Object obj = PoiPublicUtil.getRealValue(currentText, map); | |||
if (obj instanceof WordImageEntity) {// 如果是图片就设置为图片 | |||
if (obj instanceof ImageEntity) {// 如果是图片就设置为图片 | |||
currentRun.setText("", 0); | |||
addAnImage((WordImageEntity) obj, currentRun); | |||
addAnImage((ImageEntity) obj, currentRun); | |||
} else { | |||
currentText = obj.toString(); | |||
PoiPublicUtil.setWordText(currentRun, currentText); | |||