@@ -12,7 +12,6 @@ import org.jeecgframework.poi.excel.entity.ExportParams; | |||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams; | import org.jeecgframework.poi.excel.entity.TemplateExportParams; | ||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | ||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | ||||
import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | |||||
import org.jeecgframework.poi.excel.export.ExcelExportServer; | import org.jeecgframework.poi.excel.export.ExcelExportServer; | ||||
import org.jeecgframework.poi.excel.export.template.ExcelExportOfTemplateUtil; | import org.jeecgframework.poi.excel.export.template.ExcelExportOfTemplateUtil; | ||||
@@ -85,8 +84,8 @@ public final class ExcelExportUtil { | |||||
} else { | } else { | ||||
workbook = new XSSFWorkbook(); | workbook = new XSSFWorkbook(); | ||||
} | } | ||||
ExcelExportServer server = new ExcelExportServer(); | |||||
for (Map<String, Object> map : list) { | for (Map<String, Object> map : list) { | ||||
ExcelExportServer server = new ExcelExportServer(); | |||||
server.createSheet(workbook, (ExportParams) map.get("title"), | server.createSheet(workbook, (ExportParams) map.get("title"), | ||||
(Class<?>) map.get("entity"), (Collection<?>) map.get("data")); | (Class<?>) map.get("entity"), (Collection<?>) map.get("data")); | ||||
} | } | ||||
@@ -2,6 +2,7 @@ package org.jeecgframework.poi.excel.entity; | |||||
import org.apache.poi.hssf.util.HSSFColor; | import org.apache.poi.hssf.util.HSSFColor; | ||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | ||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; | |||||
/** | /** | ||||
* Excel 导出参数 | * Excel 导出参数 | ||||
@@ -19,7 +20,7 @@ public class ExportParams extends ExcelBaseParams { | |||||
/** | /** | ||||
* 表格名称 | * 表格名称 | ||||
*/ | */ | ||||
private short titleHeight = 20; | |||||
private short titleHeight = 10; | |||||
/** | /** | ||||
* 第二行名称 | * 第二行名称 | ||||
@@ -58,6 +59,10 @@ public class ExportParams extends ExcelBaseParams { | |||||
* Excel 导出版本 | * Excel 导出版本 | ||||
*/ | */ | ||||
private ExcelType type = ExcelType.HSSF; | private ExcelType type = ExcelType.HSSF; | ||||
/** | |||||
* Excel 导出style | |||||
*/ | |||||
private Class<?> style = ExcelExportStylerDefaultImpl.class; | |||||
public ExportParams() { | public ExportParams() { | ||||
@@ -168,4 +173,12 @@ public class ExportParams extends ExcelBaseParams { | |||||
this.indexName = indexName; | this.indexName = indexName; | ||||
} | } | ||||
public Class<?> getStyle() { | |||||
return style; | |||||
} | |||||
public void setStyle(Class<?> style) { | |||||
this.style = style; | |||||
} | |||||
} | } |
@@ -1,5 +1,7 @@ | |||||
package org.jeecgframework.poi.excel.entity; | package org.jeecgframework.poi.excel.entity; | ||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; | |||||
/** | /** | ||||
* 模板导出参数设置 | * 模板导出参数设置 | ||||
* | * | ||||
@@ -12,27 +14,31 @@ public class TemplateExportParams extends ExcelBaseParams { | |||||
/** | /** | ||||
* 模板的路径 | * 模板的路径 | ||||
*/ | */ | ||||
private String templateUrl; | |||||
private String templateUrl; | |||||
/** | /** | ||||
* 需要导出的第几个 sheetNum,默认是第0个 | * 需要导出的第几个 sheetNum,默认是第0个 | ||||
*/ | */ | ||||
private int sheetNum = 0; | |||||
private int sheetNum = 0; | |||||
/** | /** | ||||
* 这只sheetName 不填就使用原来的 | * 这只sheetName 不填就使用原来的 | ||||
*/ | */ | ||||
private String sheetName; | |||||
private String sheetName; | |||||
/** | /** | ||||
* 表格列标题行数,默认1 | * 表格列标题行数,默认1 | ||||
*/ | */ | ||||
private int headingRows = 1; | |||||
private int headingRows = 1; | |||||
/** | /** | ||||
* 表格列标题开始行,默认1 | * 表格列标题开始行,默认1 | ||||
*/ | */ | ||||
private int headingStartRow = 1; | |||||
private int headingStartRow = 1; | |||||
/** | |||||
* Excel 导出style | |||||
*/ | |||||
private Class<?> style = ExcelExportStylerDefaultImpl.class; | |||||
public TemplateExportParams() { | public TemplateExportParams() { | ||||
@@ -41,14 +47,17 @@ public class TemplateExportParams extends ExcelBaseParams { | |||||
public TemplateExportParams(String templateUrl) { | public TemplateExportParams(String templateUrl) { | ||||
this.templateUrl = templateUrl; | this.templateUrl = templateUrl; | ||||
} | } | ||||
public TemplateExportParams(String templateUrl, int sheetNum) { | public TemplateExportParams(String templateUrl, int sheetNum) { | ||||
this.templateUrl = templateUrl; | this.templateUrl = templateUrl; | ||||
this.sheetNum = sheetNum; | this.sheetNum = sheetNum; | ||||
} | } | ||||
public TemplateExportParams(String templateUrl, String sheetName) { | public TemplateExportParams(String templateUrl, String sheetName) { | ||||
this.templateUrl = templateUrl; | this.templateUrl = templateUrl; | ||||
this.sheetName = sheetName; | this.sheetName = sheetName; | ||||
} | } | ||||
public TemplateExportParams(String templateUrl, String sheetName, int sheetNum) { | public TemplateExportParams(String templateUrl, String sheetName, int sheetNum) { | ||||
this.templateUrl = templateUrl; | this.templateUrl = templateUrl; | ||||
this.sheetName = sheetName; | this.sheetName = sheetName; | ||||
@@ -95,4 +104,12 @@ public class TemplateExportParams extends ExcelBaseParams { | |||||
this.templateUrl = templateUrl; | this.templateUrl = templateUrl; | ||||
} | } | ||||
public Class<?> getStyle() { | |||||
return style; | |||||
} | |||||
public void setStyle(Class<?> style) { | |||||
this.style = style; | |||||
} | |||||
} | } |
@@ -0,0 +1,34 @@ | |||||
package org.jeecgframework.poi.excel.entity.enmus; | |||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerBorderImpl; | |||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerColorImpl; | |||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; | |||||
/** | |||||
* 插件提供的几个默认样式 | |||||
* @author JueYue | |||||
* @date 2015年1月9日 下午9:02:24 | |||||
*/ | |||||
public enum ExcelStyleType { | |||||
NONE("默认样式", ExcelExportStylerDefaultImpl.class), | |||||
BORDER("边框样式", ExcelExportStylerBorderImpl.class), | |||||
COLOR("间隔行样式", ExcelExportStylerColorImpl.class); | |||||
private String name; | |||||
private Class<?> clazz; | |||||
ExcelStyleType(String name, Class<?> clazz) { | |||||
this.name = name; | |||||
this.clazz = clazz; | |||||
} | |||||
public Class<?> getClazz() { | |||||
return clazz; | |||||
} | |||||
public String getName() { | |||||
return name; | |||||
} | |||||
} |
@@ -8,5 +8,5 @@ package org.jeecgframework.poi.excel.entity.enmus; | |||||
public enum ExcelType { | public enum ExcelType { | ||||
HSSF, XSSF; | HSSF, XSSF; | ||||
} | } |
@@ -4,15 +4,12 @@ import java.lang.reflect.Field; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collection; | import java.util.Collection; | ||||
import java.util.HashMap; | |||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | import java.util.Map; | ||||
import org.apache.poi.ss.usermodel.BuiltinFormats; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | import org.apache.poi.ss.usermodel.CellStyle; | ||||
import org.apache.poi.ss.usermodel.Drawing; | import org.apache.poi.ss.usermodel.Drawing; | ||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Row; | import org.apache.poi.ss.usermodel.Row; | ||||
import org.apache.poi.ss.usermodel.Sheet; | import org.apache.poi.ss.usermodel.Sheet; | ||||
import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
@@ -23,6 +20,8 @@ import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | |||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | ||||
import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | ||||
import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | ||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; | |||||
import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler; | |||||
import org.jeecgframework.poi.exception.excel.ExcelExportException; | import org.jeecgframework.poi.exception.excel.ExcelExportException; | ||||
import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | ||||
import org.jeecgframework.poi.util.POIPublicUtil; | import org.jeecgframework.poi.util.POIPublicUtil; | ||||
@@ -37,12 +36,10 @@ import org.slf4j.LoggerFactory; | |||||
*/ | */ | ||||
public class ExcelExportServer extends ExcelExportBase { | public class ExcelExportServer extends ExcelExportBase { | ||||
private final static Logger logger = LoggerFactory.getLogger(ExcelExportServer.class); | |||||
private static final short cellFormat = (short) BuiltinFormats.getBuiltinFormat("TEXT"); | |||||
private final static Logger logger = LoggerFactory.getLogger(ExcelExportServer.class); | |||||
// 最大行数,超过自动多Sheet | // 最大行数,超过自动多Sheet | ||||
private int MAX_NUM = 60000; | |||||
private int MAX_NUM = 60000; | |||||
private int createHeaderAndTitle(ExportParams entity, Sheet sheet, Workbook workbook, | private int createHeaderAndTitle(ExportParams entity, Sheet sheet, Workbook workbook, | ||||
List<ExcelExportEntity> excelParams) { | List<ExcelExportEntity> excelParams) { | ||||
@@ -66,7 +63,12 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
public int createHeaderRow(ExportParams entity, Sheet sheet, Workbook workbook, int feildWidth) { | public int createHeaderRow(ExportParams entity, Sheet sheet, Workbook workbook, int feildWidth) { | ||||
Row row = sheet.createRow(0); | Row row = sheet.createRow(0); | ||||
row.setHeight(entity.getTitleHeight()); | row.setHeight(entity.getTitleHeight()); | ||||
createStringCell(row, 0, entity.getTitle(), getHeaderStyle(workbook, entity), null); | |||||
createStringCell(row, 0, entity.getTitle(), | |||||
getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null); | |||||
for (int i = 1; i <= feildWidth; i++) { | |||||
createStringCell(row, i, "", | |||||
getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null); | |||||
} | |||||
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, feildWidth)); | sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, feildWidth)); | ||||
if (entity.getSecondTitle() != null) { | if (entity.getSecondTitle() != null) { | ||||
row = sheet.createRow(1); | row = sheet.createRow(1); | ||||
@@ -74,6 +76,10 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
CellStyle style = workbook.createCellStyle(); | CellStyle style = workbook.createCellStyle(); | ||||
style.setAlignment(CellStyle.ALIGN_RIGHT); | style.setAlignment(CellStyle.ALIGN_RIGHT); | ||||
createStringCell(row, 0, entity.getSecondTitle(), style, null); | createStringCell(row, 0, entity.getSecondTitle(), style, null); | ||||
for (int i = 1; i <= feildWidth; i++) { | |||||
createStringCell(row, i, "", | |||||
getExcelExportStyler().getHeaderStyle(entity.getHeaderColor()), null); | |||||
} | |||||
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, feildWidth)); | sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, feildWidth)); | ||||
return 2; | return 2; | ||||
} | } | ||||
@@ -106,8 +112,9 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
if (dataHanlder != null) { | if (dataHanlder != null) { | ||||
needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields()); | needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields()); | ||||
} | } | ||||
// 创建表格属性 | |||||
Map<String, CellStyle> styles = createStyles(workbook); | |||||
// 创建表格样式 | |||||
setExcelExportStyler((IExcelExportStyler) entity.getStyle() | |||||
.getConstructor(Workbook.class).newInstance(workbook)); | |||||
Drawing patriarch = sheet.createDrawingPatriarch(); | Drawing patriarch = sheet.createDrawingPatriarch(); | ||||
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | ||||
if (entity.isAddIndex()) { | if (entity.isAddIndex()) { | ||||
@@ -128,8 +135,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
List<Object> tempList = new ArrayList<Object>(); | List<Object> tempList = new ArrayList<Object>(); | ||||
while (its.hasNext()) { | while (its.hasNext()) { | ||||
Object t = its.next(); | Object t = its.next(); | ||||
index += createCells(patriarch, index, t, excelParams, sheet, workbook, styles, | |||||
rowHeight); | |||||
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight); | |||||
tempList.add(t); | tempList.add(t); | ||||
if (index >= MAX_NUM) | if (index >= MAX_NUM) | ||||
break; | break; | ||||
@@ -142,7 +148,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
its.remove(); | its.remove(); | ||||
} | } | ||||
// 创建合计信息 | // 创建合计信息 | ||||
addStatisticsRow(styles.get("one"), sheet); | |||||
addStatisticsRow(getExcelExportStyler().getStyles(true, true), sheet); | |||||
// 发现还有剩余list 继续循环创建Sheet | // 发现还有剩余list 继续循环创建Sheet | ||||
if (dataSet.size() > 0) { | if (dataSet.size() > 0) { | ||||
@@ -151,7 +157,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
logger.error(e.getMessage(),e); | |||||
logger.error(e.getMessage(), e); | |||||
throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause()); | throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause()); | ||||
} | } | ||||
} | } | ||||
@@ -182,8 +188,9 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
if (dataHanlder != null) { | if (dataHanlder != null) { | ||||
needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields()); | needHanlderList = Arrays.asList(dataHanlder.getNeedHandlerFields()); | ||||
} | } | ||||
// 创建表格属性 | |||||
Map<String, CellStyle> styles = createStyles(workbook); | |||||
// 创建表格样式 | |||||
setExcelExportStyler((IExcelExportStyler) entity.getStyle() | |||||
.getConstructor(Workbook.class).newInstance(workbook)); | |||||
Drawing patriarch = sheet.createDrawingPatriarch(); | Drawing patriarch = sheet.createDrawingPatriarch(); | ||||
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | ||||
if (entity.isAddIndex()) { | if (entity.isAddIndex()) { | ||||
@@ -200,8 +207,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
List<Object> tempList = new ArrayList<Object>(); | List<Object> tempList = new ArrayList<Object>(); | ||||
while (its.hasNext()) { | while (its.hasNext()) { | ||||
Object t = its.next(); | Object t = its.next(); | ||||
index += createCells(patriarch, index, t, excelParams, sheet, workbook, styles, | |||||
rowHeight); | |||||
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight); | |||||
tempList.add(t); | tempList.add(t); | ||||
if (index >= MAX_NUM) | if (index >= MAX_NUM) | ||||
break; | break; | ||||
@@ -219,20 +225,11 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
logger.error(e.getMessage(),e); | |||||
logger.error(e.getMessage(), e); | |||||
throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause()); | throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, e.getCause()); | ||||
} | } | ||||
} | } | ||||
private Map<String, CellStyle> createStyles(Workbook workbook) { | |||||
Map<String, CellStyle> map = new HashMap<String, CellStyle>(); | |||||
map.put("one", getOneStyle(workbook, false)); | |||||
map.put("oneWrap", getOneStyle(workbook, true)); | |||||
map.put("two", getTwoStyle(workbook, false)); | |||||
map.put("twoWrap", getTwoStyle(workbook, true)); | |||||
return map; | |||||
} | |||||
/** | /** | ||||
* 创建表头 | * 创建表头 | ||||
* | * | ||||
@@ -250,7 +247,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
listRow.setHeight((short) 450); | listRow.setHeight((short) 450); | ||||
} | } | ||||
int cellIndex = 0; | int cellIndex = 0; | ||||
CellStyle titleStyle = getTitleStyle(workbook, title); | |||||
CellStyle titleStyle = getExcelExportStyler().getTitleStyle(title.getColor()); | |||||
for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) { | for (int i = 0, exportFieldTitleSize = excelParams.size(); i < exportFieldTitleSize; i++) { | ||||
ExcelExportEntity entity = excelParams.get(i); | ExcelExportEntity entity = excelParams.get(i); | ||||
createStringCell(row, cellIndex, entity.getName(), titleStyle, entity); | createStringCell(row, cellIndex, entity.getName(), titleStyle, entity); | ||||
@@ -265,6 +262,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
cellIndex++; | cellIndex++; | ||||
} | } | ||||
} else if (rows == 2) { | } else if (rows == 2) { | ||||
createStringCell(listRow, cellIndex, "", titleStyle, entity); | |||||
sheet.addMergedRegion(new CellRangeAddress(index, index + 1, cellIndex, cellIndex)); | sheet.addMergedRegion(new CellRangeAddress(index, index + 1, cellIndex, cellIndex)); | ||||
} | } | ||||
cellIndex++; | cellIndex++; | ||||
@@ -273,38 +271,6 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
} | } | ||||
/** | |||||
* 表明的Style | |||||
* | |||||
* @param workbook | |||||
* @return | |||||
*/ | |||||
public CellStyle getHeaderStyle(Workbook workbook, ExportParams entity) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
Font font = workbook.createFont(); | |||||
font.setFontHeightInPoints((short) 24); | |||||
titleStyle.setFont(font); | |||||
titleStyle.setFillForegroundColor(entity.getColor()); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
return titleStyle; | |||||
} | |||||
public CellStyle getOneStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
/** | /** | ||||
* 判断表头是只有一行还是两行 | * 判断表头是只有一行还是两行 | ||||
* | * | ||||
@@ -320,52 +286,6 @@ public class ExcelExportServer extends ExcelExportBase { | |||||
return 1; | return 1; | ||||
} | } | ||||
public CellStyle getStyles(Map<String, CellStyle> map, boolean needOne, boolean isWrap) { | |||||
if (needOne && isWrap) { | |||||
return map.get("oneWrap"); | |||||
} | |||||
if (needOne) { | |||||
return map.get("one"); | |||||
} | |||||
if (needOne == false && isWrap) { | |||||
return map.get("twoWrap"); | |||||
} | |||||
return map.get("two"); | |||||
} | |||||
/** | |||||
* 字段说明的Style | |||||
* | |||||
* @param workbook | |||||
* @return | |||||
*/ | |||||
public CellStyle getTitleStyle(Workbook workbook, ExportParams entity) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
titleStyle.setFillForegroundColor(entity.getHeaderColor()); // 填充的背景颜色 | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
titleStyle.setWrapText(true); | |||||
return titleStyle; | |||||
} | |||||
public CellStyle getTwoStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setFillForegroundColor((short) 41); // 填充的背景颜色 | |||||
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
private ExcelExportEntity indexExcelEntity(ExportParams entity) { | private ExcelExportEntity indexExcelEntity(ExportParams entity) { | ||||
ExcelExportEntity exportEntity = new ExcelExportEntity(); | ExcelExportEntity exportEntity = new ExcelExportEntity(); | ||||
exportEntity.setOrderNum(0); | exportEntity.setOrderNum(0); | ||||
@@ -32,10 +32,11 @@ import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | |||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | ||||
import org.jeecgframework.poi.excel.entity.params.MergeEntity; | import org.jeecgframework.poi.excel.entity.params.MergeEntity; | ||||
import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | ||||
import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler; | |||||
import org.jeecgframework.poi.util.POIPublicUtil; | import org.jeecgframework.poi.util.POIPublicUtil; | ||||
/** | /** | ||||
* 导出基础服务 | |||||
* 提供POI基础操作服务 | |||||
* | * | ||||
* @author JueYue | * @author JueYue | ||||
* @date 2014年6月17日 下午6:15:13 | * @date 2014年6月17日 下午6:15:13 | ||||
@@ -50,6 +51,8 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); | private static final DecimalFormat DOUBLE_FORMAT = new DecimalFormat("######0.00"); | ||||
private IExcelExportStyler excelExportStyler; | |||||
private boolean checkIsEqualByCellContents(MergeEntity mergeEntity, String text, Cell cell, | private boolean checkIsEqualByCellContents(MergeEntity mergeEntity, String text, Cell cell, | ||||
int[] delys, int rowNum) { | int[] delys, int rowNum) { | ||||
// 没有依赖关系 | // 没有依赖关系 | ||||
@@ -78,12 +81,12 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
*/ | */ | ||||
public int createCells(Drawing patriarch, int index, Object t, | public int createCells(Drawing patriarch, int index, Object t, | ||||
List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook, | List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook, | ||||
Map<String, CellStyle> styles, short rowHeight) throws Exception { | |||||
short rowHeight) throws Exception { | |||||
ExcelExportEntity entity; | ExcelExportEntity entity; | ||||
Row row = sheet.createRow(index); | Row row = sheet.createRow(index); | ||||
row.setHeight(rowHeight); | row.setHeight(rowHeight); | ||||
int maxHeight = 1, cellNum = 0; | int maxHeight = 1, cellNum = 0; | ||||
int indexKey = createIndexCell(row, styles, index, excelParams.get(0)); | |||||
int indexKey = createIndexCell(row, index, excelParams.get(0)); | |||||
cellNum += indexKey; | cellNum += indexKey; | ||||
for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { | for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { | ||||
entity = excelParams.get(k); | entity = excelParams.get(k); | ||||
@@ -92,7 +95,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
int listC = 0; | int listC = 0; | ||||
for (Object obj : list) { | for (Object obj : list) { | ||||
createListCells(patriarch, index + listC, cellNum, obj, entity.getList(), | createListCells(patriarch, index + listC, cellNum, obj, entity.getList(), | ||||
sheet, workbook, styles); | |||||
sheet, workbook); | |||||
listC++; | listC++; | ||||
} | } | ||||
cellNum += entity.getList().size(); | cellNum += entity.getList().size(); | ||||
@@ -106,8 +109,8 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
row, | row, | ||||
cellNum++, | cellNum++, | ||||
value == null ? "" : value.toString(), | value == null ? "" : value.toString(), | ||||
index % 2 == 0 ? getStyles(styles, false, entity.isWrap()) : getStyles( | |||||
styles, true, entity.isWrap()), entity); | |||||
index % 2 == 0 ? getStyles(false, entity.isWrap()) : getStyles(true, | |||||
entity.isWrap()), entity); | |||||
} else { | } else { | ||||
createImageCell(patriarch, entity, row, cellNum++, | createImageCell(patriarch, entity, row, cellNum++, | ||||
value == null ? "" : value.toString(), t); | value == null ? "" : value.toString(), t); | ||||
@@ -124,7 +127,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
for (int i = index + 1; i < index + maxHeight; i++) { | for (int i = index + 1; i < index + maxHeight; i++) { | ||||
sheet.getRow(i).createCell(cellNum); | sheet.getRow(i).createCell(cellNum); | ||||
sheet.getRow(i).getCell(cellNum) | sheet.getRow(i).getCell(cellNum) | ||||
.setCellStyle(getStyles(styles, false, entity.isWrap())); | |||||
.setCellStyle(getStyles(false, entity.isWrap())); | |||||
} | } | ||||
sheet.addMergedRegion(new CellRangeAddress(index, index + maxHeight - 1, cellNum, | sheet.addMergedRegion(new CellRangeAddress(index, index + maxHeight - 1, cellNum, | ||||
cellNum)); | cellNum)); | ||||
@@ -190,13 +193,11 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
} | } | ||||
private int createIndexCell(Row row, Map<String, CellStyle> styles, int index, | |||||
ExcelExportEntity excelExportEntity) { | |||||
private int createIndexCell(Row row, int index, ExcelExportEntity excelExportEntity) { | |||||
if (excelExportEntity.getName().equals("序号") | if (excelExportEntity.getName().equals("序号") | ||||
&& excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) { | && excelExportEntity.getFormat().equals(PoiBaseConstants.IS_ADD_INDEX)) { | ||||
createStringCell(row, 0, currentIndex + "", | |||||
index % 2 == 0 ? getStyles(styles, false, false) : getStyles(styles, true, false), | |||||
null); | |||||
createStringCell(row, 0, currentIndex + "", index % 2 == 0 ? getStyles(false, false) | |||||
: getStyles(true, false), null); | |||||
currentIndex = currentIndex + 1; | currentIndex = currentIndex + 1; | ||||
return 1; | return 1; | ||||
} | } | ||||
@@ -209,8 +210,8 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
* @param styles | * @param styles | ||||
*/ | */ | ||||
public void createListCells(Drawing patriarch, int index, int cellNum, Object obj, | public void createListCells(Drawing patriarch, int index, int cellNum, Object obj, | ||||
List<ExcelExportEntity> excelParams, Sheet sheet, | |||||
Workbook workbook, Map<String, CellStyle> styles) throws Exception { | |||||
List<ExcelExportEntity> excelParams, Sheet sheet, Workbook workbook) | |||||
throws Exception { | |||||
ExcelExportEntity entity; | ExcelExportEntity entity; | ||||
Row row; | Row row; | ||||
if (sheet.getRow(index) == null) { | if (sheet.getRow(index) == null) { | ||||
@@ -223,9 +224,12 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
entity = excelParams.get(k); | entity = excelParams.get(k); | ||||
Object value = getCellValue(entity, obj); | Object value = getCellValue(entity, obj); | ||||
if (entity.getType() == 1) { | if (entity.getType() == 1) { | ||||
createStringCell(row, cellNum++, value == null ? "" : value.toString(), | |||||
row.getRowNum() % 2 == 0 ? getStyles(styles, false, entity.isWrap()) | |||||
: getStyles(styles, true, entity.isWrap()), entity); | |||||
createStringCell( | |||||
row, | |||||
cellNum++, | |||||
value == null ? "" : value.toString(), | |||||
row.getRowNum() % 2 == 0 ? getStyles(false, entity.isWrap()) : getStyles(true, | |||||
entity.isWrap()), entity); | |||||
} else { | } else { | ||||
createImageCell(patriarch, entity, row, cellNum++, | createImageCell(patriarch, entity, row, cellNum++, | ||||
value == null ? "" : value.toString(), obj); | value == null ? "" : value.toString(), obj); | ||||
@@ -376,8 +380,14 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
return mergeMap; | return mergeMap; | ||||
} | } | ||||
public CellStyle getStyles(Map<String, CellStyle> styles, boolean needOne, boolean wrap) { | |||||
return null; | |||||
/** | |||||
* 获取样式 | |||||
* @param needOne | |||||
* @param isWrap | |||||
* @return | |||||
*/ | |||||
public CellStyle getStyles(boolean needOne, boolean isWrap) { | |||||
return excelExportStyler.getStyles(needOne, isWrap); | |||||
} | } | ||||
/** | /** | ||||
@@ -485,4 +495,12 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
this.currentIndex = currentIndex; | this.currentIndex = currentIndex; | ||||
} | } | ||||
public void setExcelExportStyler(IExcelExportStyler excelExportStyler) { | |||||
this.excelExportStyler = excelExportStyler; | |||||
} | |||||
public IExcelExportStyler getExcelExportStyler() { | |||||
return excelExportStyler; | |||||
} | |||||
} | } |
@@ -0,0 +1,54 @@ | |||||
package org.jeecgframework.poi.excel.export.styler; | |||||
import org.apache.poi.ss.usermodel.BuiltinFormats; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
/** | |||||
* 抽象接口提供两个公共方法 | |||||
* @author JueYue | |||||
* @date 2015年1月9日 下午5:48:55 | |||||
*/ | |||||
public abstract class AbstractExcelExportStyler implements IExcelExportStyler { | |||||
protected CellStyle oneStyle; | |||||
protected CellStyle oneWrapStyle; | |||||
protected CellStyle doubleStyle; | |||||
protected CellStyle doubleWrapStyle; | |||||
protected Workbook workbook; | |||||
protected static final short cellFormat = (short) BuiltinFormats.getBuiltinFormat("TEXT"); | |||||
protected void createStyles(Workbook workbook) { | |||||
this.oneStyle = createOneStyle(workbook, false); | |||||
this.oneWrapStyle = createOneStyle(workbook, true); | |||||
this.doubleStyle = createDoubleStyle(workbook, false); | |||||
this.doubleWrapStyle = createDoubleStyle(workbook, true); | |||||
this.workbook = workbook; | |||||
} | |||||
@Override | |||||
public CellStyle getStyles(boolean needOne, boolean isWrap) { | |||||
if (needOne && isWrap) { | |||||
return oneWrapStyle; | |||||
} | |||||
if (needOne) { | |||||
return oneStyle; | |||||
} | |||||
if (needOne == false && isWrap) { | |||||
return doubleWrapStyle; | |||||
} | |||||
return doubleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createOneStyle(Workbook workbook, boolean isWarp) { | |||||
return null; | |||||
} | |||||
@Override | |||||
public CellStyle createDoubleStyle(Workbook workbook, boolean isWarp) { | |||||
return null; | |||||
} | |||||
} |
@@ -0,0 +1,68 @@ | |||||
package org.jeecgframework.poi.excel.export.styler; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
/** | |||||
* 带有边框的Excel样式 | |||||
* @author JueYue | |||||
* @date 2015年1月9日 下午5:55:29 | |||||
*/ | |||||
public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler implements | |||||
IExcelExportStyler { | |||||
public ExcelExportStylerBorderImpl(Workbook workbook) { | |||||
super.createStyles(workbook); | |||||
} | |||||
@Override | |||||
public CellStyle getHeaderStyle(short color) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
Font font = workbook.createFont(); | |||||
font.setFontHeightInPoints((short) 12); | |||||
titleStyle.setFont(font); | |||||
titleStyle.setBorderLeft((short) 1); // 左边框 | |||||
titleStyle.setBorderRight((short) 1); // 右边框 | |||||
titleStyle.setBorderBottom((short) 1); | |||||
titleStyle.setBorderTop((short) 1); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
return titleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createOneStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
@Override | |||||
public CellStyle getTitleStyle(short color) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
titleStyle.setBorderLeft((short) 1); // 左边框 | |||||
titleStyle.setBorderRight((short) 1); // 右边框 | |||||
titleStyle.setBorderBottom((short) 1); | |||||
titleStyle.setBorderTop((short) 1); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setWrapText(true); | |||||
return titleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createDoubleStyle(Workbook workbook, boolean isWarp) { | |||||
return isWarp ? oneWrapStyle : oneStyle; | |||||
} | |||||
} |
@@ -0,0 +1,76 @@ | |||||
package org.jeecgframework.poi.excel.export.styler; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
/** | |||||
* 带有样式的导出服务 | |||||
* @author JueYue | |||||
* @date 2015年1月9日 下午4:54:15 | |||||
*/ | |||||
public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler implements | |||||
IExcelExportStyler { | |||||
public ExcelExportStylerColorImpl(Workbook workbook) { | |||||
super.createStyles(workbook); | |||||
} | |||||
@Override | |||||
public CellStyle getHeaderStyle(short headerColor) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
Font font = workbook.createFont(); | |||||
font.setFontHeightInPoints((short) 24); | |||||
titleStyle.setFont(font); | |||||
titleStyle.setFillForegroundColor(headerColor); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
return titleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createOneStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
@Override | |||||
public CellStyle getTitleStyle(short color) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
titleStyle.setFillForegroundColor(color); // 填充的背景颜色 | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
titleStyle.setWrapText(true); | |||||
return titleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createDoubleStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setBorderLeft((short) 1); // 左边框 | |||||
style.setBorderRight((short) 1); // 右边框 | |||||
style.setBorderBottom((short) 1); | |||||
style.setBorderTop((short) 1); | |||||
style.setFillForegroundColor((short) 41); // 填充的背景颜色 | |||||
style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
} |
@@ -0,0 +1,63 @@ | |||||
package org.jeecgframework.poi.excel.export.styler; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Font; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
/** | |||||
* 样式的默认实现 | |||||
* @author JueYue | |||||
* @date 2015年1月9日 下午5:36:08 | |||||
*/ | |||||
public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler implements | |||||
IExcelExportStyler { | |||||
public ExcelExportStylerDefaultImpl(Workbook workbook) { | |||||
super.createStyles(workbook); | |||||
} | |||||
@Override | |||||
public CellStyle getTitleStyle(short color) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
titleStyle.setWrapText(true); | |||||
return titleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createDoubleStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
@Override | |||||
public CellStyle getHeaderStyle(short color) { | |||||
CellStyle titleStyle = workbook.createCellStyle(); | |||||
Font font = workbook.createFont(); | |||||
font.setFontHeightInPoints((short) 12); | |||||
titleStyle.setFont(font); | |||||
titleStyle.setAlignment(CellStyle.ALIGN_CENTER); | |||||
titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
return titleStyle; | |||||
} | |||||
@Override | |||||
public CellStyle createOneStyle(Workbook workbook, boolean isWarp) { | |||||
CellStyle style = workbook.createCellStyle(); | |||||
style.setAlignment(CellStyle.ALIGN_CENTER); | |||||
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); | |||||
style.setDataFormat(cellFormat); | |||||
if (isWarp) { | |||||
style.setWrapText(true); | |||||
} | |||||
return style; | |||||
} | |||||
} |
@@ -0,0 +1,52 @@ | |||||
package org.jeecgframework.poi.excel.export.styler; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
/** | |||||
* Excel导出样式接口 | |||||
* @author JueYue | |||||
* @date 2015年1月9日 下午5:32:30 | |||||
*/ | |||||
public interface IExcelExportStyler { | |||||
/** | |||||
* 列表头样式 | |||||
* @param headerColor | |||||
* @return | |||||
*/ | |||||
public CellStyle getHeaderStyle(short headerColor); | |||||
/** | |||||
* 标题样式 | |||||
* @param color | |||||
* @return | |||||
*/ | |||||
public CellStyle getTitleStyle(short color); | |||||
/** | |||||
* 获取样式方法 | |||||
* @param map | |||||
* @param needOne | |||||
* @param isWrap | |||||
* @return | |||||
*/ | |||||
public CellStyle getStyles(boolean needOne, boolean isWrap); | |||||
/** | |||||
* 创建样式 | |||||
* @param workbook | |||||
* @param isWarp | |||||
* @return | |||||
*/ | |||||
public CellStyle createOneStyle(Workbook workbook, boolean isWarp); | |||||
/** | |||||
* 创建双行样式 | |||||
* @param workbook | |||||
* @param isWarp | |||||
* @return | |||||
*/ | |||||
public CellStyle createDoubleStyle(Workbook workbook, boolean isWarp); | |||||
} |
@@ -22,6 +22,7 @@ import org.jeecgframework.poi.excel.entity.TemplateExportParams; | |||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | ||||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | ||||
import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | ||||
import org.jeecgframework.poi.excel.export.styler.IExcelExportStyler; | |||||
import org.jeecgframework.poi.exception.excel.ExcelExportException; | import org.jeecgframework.poi.exception.excel.ExcelExportException; | ||||
import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | ||||
import org.jeecgframework.poi.util.POIPublicUtil; | import org.jeecgframework.poi.util.POIPublicUtil; | ||||
@@ -64,6 +65,9 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||||
if (etarget != null) { | if (etarget != null) { | ||||
targetId = etarget.value(); | targetId = etarget.value(); | ||||
} | } | ||||
// 创建表格样式 | |||||
setExcelExportStyler((IExcelExportStyler) params.getStyle().getConstructor(Workbook.class) | |||||
.newInstance(workbook)); | |||||
// 获取实体对象的导出数据 | // 获取实体对象的导出数据 | ||||
List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | ||||
getAllExcelField(null, targetId, fileds, excelParams, pojoClass, null); | getAllExcelField(null, targetId, fileds, excelParams, pojoClass, null); | ||||
@@ -78,7 +82,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||||
Iterator<?> its = dataSet.iterator(); | Iterator<?> its = dataSet.iterator(); | ||||
while (its.hasNext()) { | while (its.hasNext()) { | ||||
Object t = its.next(); | Object t = its.next(); | ||||
index += createCells(patriarch, index, t, excelParams, sheet, workbook, null, rowHeight); | |||||
index += createCells(patriarch, index, t, excelParams, sheet, workbook, rowHeight); | |||||
} | } | ||||
// 合并同类项 | // 合并同类项 | ||||
mergeCells(sheet, excelParams, titleHeight); | mergeCells(sheet, excelParams, titleHeight); | ||||
@@ -148,7 +152,7 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||||
addDataToSheet(params, pojoClass, dataSet, wb.getSheetAt(0), wb); | addDataToSheet(params, pojoClass, dataSet, wb.getSheetAt(0), wb); | ||||
} | } | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
LOGGER.error(e.getMessage(),e); | |||||
LOGGER.error(e.getMessage(), e); | |||||
return null; | return null; | ||||
} | } | ||||
return wb; | return wb; | ||||
@@ -12,6 +12,7 @@ import org.jeecgframework.poi.handler.inter.IExcelVerifyHandler; | |||||
* @date 2014年6月29日 下午4:37:56 | * @date 2014年6月29日 下午4:37:56 | ||||
*/ | */ | ||||
public class VerifyHandlerServer { | public class VerifyHandlerServer { | ||||
private void addVerifyResult(ExcelVerifyHanlderResult temp, ExcelVerifyHanlderResult result) { | private void addVerifyResult(ExcelVerifyHanlderResult temp, ExcelVerifyHanlderResult result) { | ||||
if (!temp.isSuccess()) { | if (!temp.isSuccess()) { | ||||
result.setSuccess(false); | result.setSuccess(false); | ||||
@@ -41,6 +41,10 @@ public interface IExcelDataHandler { | |||||
*/ | */ | ||||
public Object importHandler(Object obj, String name, Object value); | public Object importHandler(Object obj, String name, Object value); | ||||
/** | |||||
* 设置需要处理的属性列表 | |||||
* @param fields | |||||
*/ | |||||
public void setNeedHandlerFields(String[] fields); | public void setNeedHandlerFields(String[] fields); | ||||
} | } |
@@ -1,41 +0,0 @@ | |||||
package org.jeecgframework.poi.excel; | |||||
import java.util.Map; | |||||
import org.apache.poi.ss.usermodel.CellStyle; | |||||
import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.jeecgframework.poi.excel.entity.ExportParams; | |||||
import org.jeecgframework.poi.excel.export.ExcelExportServer; | |||||
/** | |||||
* 自己定义导出的样式 | |||||
* @author JueYue | |||||
* @date 2014年12月2日 上午10:32:44 | |||||
*/ | |||||
public class MyExcelExport extends ExcelExportServer { | |||||
@Override | |||||
public CellStyle getHeaderStyle(Workbook workbook, ExportParams entity) { | |||||
return super.getHeaderStyle(workbook, entity); | |||||
} | |||||
@Override | |||||
public CellStyle getOneStyle(Workbook workbook, boolean isWarp) { | |||||
return super.getOneStyle(workbook, isWarp); | |||||
} | |||||
@Override | |||||
public CellStyle getStyles(Map<String, CellStyle> map, boolean needOne, boolean isWrap) { | |||||
return super.getStyles(map, needOne, isWrap); | |||||
} | |||||
@Override | |||||
public CellStyle getTitleStyle(Workbook workbook, ExportParams entity) { | |||||
return super.getTitleStyle(workbook, entity); | |||||
} | |||||
@Override | |||||
public CellStyle getTwoStyle(Workbook workbook, boolean isWarp) { | |||||
return super.getTwoStyle(workbook, isWarp); | |||||
} | |||||
} |
@@ -17,6 +17,9 @@ import org.jeecgframework.poi.entity.temp.PayeeEntity; | |||||
import org.jeecgframework.poi.entity.temp.TemplateExcelExportEntity; | import org.jeecgframework.poi.entity.temp.TemplateExcelExportEntity; | ||||
import org.jeecgframework.poi.excel.ExcelExportUtil; | import org.jeecgframework.poi.excel.ExcelExportUtil; | ||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams; | import org.jeecgframework.poi.excel.entity.TemplateExportParams; | ||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerBorderImpl; | |||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerColorImpl; | |||||
import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; | |||||
import org.junit.Test; | import org.junit.Test; | ||||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | ||||
@@ -29,6 +32,7 @@ public class TemplateExcelExportTest { | |||||
"org/jeecgframework/poi/excel/doc/专项支出用款申请书.xls"); | "org/jeecgframework/poi/excel/doc/专项支出用款申请书.xls"); | ||||
params.setHeadingStartRow(3); | params.setHeadingStartRow(3); | ||||
params.setHeadingRows(2); | params.setHeadingRows(2); | ||||
params.setStyle(ExcelExportStylerColorImpl.class); | |||||
Map<String, Object> map = new HashMap<String, Object>(); | Map<String, Object> map = new HashMap<String, Object>(); | ||||
map.put("date", "2014-12-25"); | map.put("date", "2014-12-25"); | ||||
map.put("money", 2000000.00); | map.put("money", 2000000.00); | ||||
@@ -40,7 +44,7 @@ public class TemplateExcelExportTest { | |||||
List<TemplateExcelExportEntity> list = new ArrayList<TemplateExcelExportEntity>(); | List<TemplateExcelExportEntity> list = new ArrayList<TemplateExcelExportEntity>(); | ||||
for (int i = 0; i < 1; i++) { | |||||
for (int i = 0; i < 4; i++) { | |||||
TemplateExcelExportEntity entity = new TemplateExcelExportEntity(); | TemplateExcelExportEntity entity = new TemplateExcelExportEntity(); | ||||
entity.setIndex(i + 1 + ""); | entity.setIndex(i + 1 + ""); | ||||
entity.setAccountType("开源项目"); | entity.setAccountType("开源项目"); | ||||
@@ -11,6 +11,7 @@ import org.apache.poi.ss.usermodel.Workbook; | |||||
import org.jeecgframework.poi.entity.statistics.StatisticEntity; | import org.jeecgframework.poi.entity.statistics.StatisticEntity; | ||||
import org.jeecgframework.poi.excel.ExcelExportUtil; | import org.jeecgframework.poi.excel.ExcelExportUtil; | ||||
import org.jeecgframework.poi.excel.entity.ExportParams; | import org.jeecgframework.poi.excel.entity.ExportParams; | ||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelStyleType; | |||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | import org.jeecgframework.poi.excel.entity.enmus.ExcelType; | ||||
import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
@@ -20,7 +21,7 @@ public class ExcelExportStatisticTest { | |||||
public void test() throws Exception { | public void test() throws Exception { | ||||
List<StatisticEntity> list = new ArrayList<StatisticEntity>(); | List<StatisticEntity> list = new ArrayList<StatisticEntity>(); | ||||
for (int i = 0; i < 25000; i++) { | |||||
for (int i = 0; i < 20; i++) { | |||||
StatisticEntity client = new StatisticEntity(); | StatisticEntity client = new StatisticEntity(); | ||||
client.setName("index" + i); | client.setName("index" + i); | ||||
client.setIntTest(1 + i); | client.setIntTest(1 + i); | ||||
@@ -32,6 +33,7 @@ public class ExcelExportStatisticTest { | |||||
} | } | ||||
Date start = new Date(); | Date start = new Date(); | ||||
ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF); | ExportParams params = new ExportParams("2412312", "测试", ExcelType.XSSF); | ||||
params.setStyle(ExcelStyleType.COLOR.getClazz()); | |||||
Workbook workbook = ExcelExportUtil.exportExcel(params, StatisticEntity.class, list); | Workbook workbook = ExcelExportUtil.exportExcel(params, StatisticEntity.class, list); | ||||
System.out.println(new Date().getTime() - start.getTime()); | System.out.println(new Date().getTime() - start.getTime()); | ||||
File savefile = new File("d:/"); | File savefile = new File("d:/"); | ||||
@@ -14,6 +14,7 @@ import org.jeecgframework.poi.entity.StudentEntity; | |||||
import org.jeecgframework.poi.entity.TeacherEntity; | import org.jeecgframework.poi.entity.TeacherEntity; | ||||
import org.jeecgframework.poi.excel.ExcelExportUtil; | import org.jeecgframework.poi.excel.ExcelExportUtil; | ||||
import org.jeecgframework.poi.excel.entity.TemplateExportParams; | import org.jeecgframework.poi.excel.entity.TemplateExportParams; | ||||
import org.jeecgframework.poi.excel.entity.enmus.ExcelStyleType; | |||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Test; | import org.junit.Test; | ||||
@@ -27,6 +28,7 @@ public class ExcelExportTemplateTest { | |||||
TemplateExportParams params = new TemplateExportParams(); | TemplateExportParams params = new TemplateExportParams(); | ||||
params.setHeadingRows(2); | params.setHeadingRows(2); | ||||
params.setHeadingStartRow(2); | params.setHeadingStartRow(2); | ||||
params.setStyle(ExcelStyleType.BORDER.getClazz()); | |||||
Map<String, Object> map = new HashMap<String, Object>(); | Map<String, Object> map = new HashMap<String, Object>(); | ||||
map.put("year", "2013"); | map.put("year", "2013"); | ||||
map.put("sunCourses", list.size()); | map.put("sunCourses", list.size()); | ||||
@@ -155,15 +155,4 @@ | |||||
</plugins> | </plugins> | ||||
</build> | </build> | ||||
<distributionManagement> | |||||
<repository> | |||||
<id>postaop-common-release</id> | |||||
<url>http://192.168.1.99:8081/nexus/content/repositories/postaop-common-release/</url> | |||||
</repository> | |||||
<snapshotRepository> | |||||
<id>postaop-common-snapshot</id> | |||||
<url>http://192.168.1.99:8081/nexus/content/repositories/postaop-common-snapshot/</url> | |||||
</snapshotRepository> | |||||
</distributionManagement> | |||||
</project> | </project> |