@@ -39,12 +39,12 @@ public class WordCache { | |||||
MyXWPFDocument doc = new MyXWPFDocument(is); | MyXWPFDocument doc = new MyXWPFDocument(is); | ||||
return doc; | return doc; | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
LOGGER.error(e.getMessage(),e); | |||||
LOGGER.error(e.getMessage(), e); | |||||
} finally { | } finally { | ||||
try { | try { | ||||
is.close(); | is.close(); | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
LOGGER.error(e.getMessage(),e); | |||||
LOGGER.error(e.getMessage(), e); | |||||
} | } | ||||
} | } | ||||
return null; | return null; | ||||
@@ -14,6 +14,7 @@ | |||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
package org.jeecgframework.poi.cache.manager; | package org.jeecgframework.poi.cache.manager; | ||||
/** | /** | ||||
* 缓存读取 | * 缓存读取 | ||||
* @author JueYue | * @author JueYue | ||||
@@ -94,8 +94,8 @@ public class ExcelImportUtil { | |||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
public static <T> ExcelImportResult<T> importExcelVerify(InputStream inputstream, | public static <T> ExcelImportResult<T> importExcelVerify(InputStream inputstream, | ||||
Class<?> pojoClass, ImportParams params) | |||||
throws Exception { | |||||
Class<?> pojoClass, | |||||
ImportParams params) throws Exception { | |||||
return new ExcelImportServer().importExcelByIs(inputstream, pojoClass, params); | return new ExcelImportServer().importExcelByIs(inputstream, pojoClass, params); | ||||
} | } | ||||
@@ -89,11 +89,12 @@ public class ExportParams extends ExcelBaseParams { | |||||
/** | /** | ||||
* 是否动态获取数据 | * 是否动态获取数据 | ||||
*/ | */ | ||||
private boolean isDynamicData = false; | |||||
private boolean isDynamicData = false; | |||||
/** | /** | ||||
* 是否追加图形 | * 是否追加图形 | ||||
*/ | */ | ||||
private boolean isAppendGraph = true; | |||||
private boolean isAppendGraph = true; | |||||
public ExportParams() { | public ExportParams() { | ||||
} | } | ||||
@@ -227,24 +228,20 @@ public class ExportParams extends ExcelBaseParams { | |||||
this.isCreateHeadRows = isCreateHeadRows; | this.isCreateHeadRows = isCreateHeadRows; | ||||
} | } | ||||
public boolean isDynamicData() | |||||
{ | |||||
return isDynamicData; | |||||
} | |||||
public boolean isDynamicData() { | |||||
return isDynamicData; | |||||
} | |||||
public void setDynamicData(boolean isDynamicData) | |||||
{ | |||||
this.isDynamicData = isDynamicData; | |||||
} | |||||
public void setDynamicData(boolean isDynamicData) { | |||||
this.isDynamicData = isDynamicData; | |||||
} | |||||
public boolean isAppendGraph() | |||||
{ | |||||
return isAppendGraph; | |||||
} | |||||
public boolean isAppendGraph() { | |||||
return isAppendGraph; | |||||
} | |||||
public void setAppendGraph(boolean isAppendGraph) | |||||
{ | |||||
this.isAppendGraph = isAppendGraph; | |||||
} | |||||
public void setAppendGraph(boolean isAppendGraph) { | |||||
this.isAppendGraph = isAppendGraph; | |||||
} | |||||
} | } |
@@ -57,7 +57,7 @@ public class ImportParams extends ExcelBaseParams { | |||||
/** | /** | ||||
* 是否需要校验上传的Excel,默认为false | * 是否需要校验上传的Excel,默认为false | ||||
*/ | */ | ||||
private boolean needVerfiy = false; | |||||
private boolean needVerfiy = false; | |||||
/** | /** | ||||
* 保存上传的Excel目录,默认是 如 TestEntity这个类保存路径就是 | * 保存上传的Excel目录,默认是 如 TestEntity这个类保存路径就是 | ||||
* upload/excelUpload/Test/yyyyMMddHHmss_***** 保存名称上传时间_五位随机数 | * upload/excelUpload/Test/yyyyMMddHHmss_***** 保存名称上传时间_五位随机数 | ||||
@@ -22,6 +22,6 @@ package org.jeecgframework.poi.excel.entity.enmus; | |||||
*/ | */ | ||||
public enum CellValueType { | public enum CellValueType { | ||||
String, Number, Boolean, Date, TElement, Null, None; | |||||
String , Number , Boolean , Date , TElement , Null , None; | |||||
} | } |
@@ -26,9 +26,9 @@ import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; | |||||
*/ | */ | ||||
public enum ExcelStyleType { | public enum ExcelStyleType { | ||||
NONE("默认样式", ExcelExportStylerDefaultImpl.class), | |||||
BORDER("边框样式", ExcelExportStylerBorderImpl.class), | |||||
COLOR("间隔行样式", ExcelExportStylerColorImpl.class); | |||||
NONE ("默认样式" , ExcelExportStylerDefaultImpl.class) , | |||||
BORDER ("边框样式" , ExcelExportStylerBorderImpl.class) , | |||||
COLOR ("间隔行样式" , ExcelExportStylerColorImpl.class); | |||||
private String name; | private String name; | ||||
private Class<?> clazz; | private Class<?> clazz; | ||||
@@ -21,7 +21,7 @@ package org.jeecgframework.poi.excel.entity.enmus; | |||||
* @date 2014年12月29日 下午9:08:21 | * @date 2014年12月29日 下午9:08:21 | ||||
*/ | */ | ||||
public enum ExcelType { | public enum ExcelType { | ||||
HSSF, XSSF; | |||||
HSSF , XSSF; | |||||
} | } |
@@ -191,28 +191,29 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc | |||||
public int compareTo(ExcelExportEntity prev) { | public int compareTo(ExcelExportEntity prev) { | ||||
return this.getOrderNum() - prev.getOrderNum(); | return this.getOrderNum() - prev.getOrderNum(); | ||||
} | } | ||||
@Override | @Override | ||||
public int hashCode() | |||||
{ | |||||
final int prime = 31; | |||||
int result = 1; | |||||
result = prime * result + ((key == null) ? 0 : key.hashCode()); | |||||
return result; | |||||
} | |||||
@Override | |||||
public boolean equals(Object obj) | |||||
{ | |||||
if (this == obj) return true; | |||||
if (obj == null) return false; | |||||
if (getClass() != obj.getClass()) return false; | |||||
ExcelExportEntity other = (ExcelExportEntity) obj; | |||||
if (key == null) | |||||
{ | |||||
if (other.key != null) return false; | |||||
} | |||||
else if (!key.equals(other.key)) return false; | |||||
return true; | |||||
} | |||||
public int hashCode() { | |||||
final int prime = 31; | |||||
int result = 1; | |||||
result = prime * result + ((key == null) ? 0 : key.hashCode()); | |||||
return result; | |||||
} | |||||
@Override | |||||
public boolean equals(Object obj) { | |||||
if (this == obj) | |||||
return true; | |||||
if (obj == null) | |||||
return false; | |||||
if (getClass() != obj.getClass()) | |||||
return false; | |||||
ExcelExportEntity other = (ExcelExportEntity) obj; | |||||
if (key == null) { | |||||
if (other.key != null) | |||||
return false; | |||||
} else if (!key.equals(other.key)) | |||||
return false; | |||||
return true; | |||||
} | |||||
} | } |
@@ -10,9 +10,8 @@ package org.jeecgframework.poi.excel.entity.vo; | |||||
* @see org.jeecgframework.poi.excel.entity.vo.BaseEntityTypeConstants | * @see org.jeecgframework.poi.excel.entity.vo.BaseEntityTypeConstants | ||||
* | * | ||||
*/ | */ | ||||
public interface BaseEntityTypeConstants | |||||
{ | |||||
public final static Integer StringType =1; | |||||
public final static Integer DoubleType =10; | |||||
public final static Integer ImageType = 3; | |||||
public interface BaseEntityTypeConstants { | |||||
public final static Integer StringType = 1; | |||||
public final static Integer DoubleType = 10; | |||||
public final static Integer ImageType = 3; | |||||
} | } |
@@ -113,19 +113,17 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
row.getSheet().getWorkbook().getCreationHelper(), t, | row.getSheet().getWorkbook().getCreationHelper(), t, | ||||
entity.getName(), value)); | 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); | |||||
if (entity.isHyperlink()) { | |||||
row.getCell(cellNum - 1) | |||||
.setHyperlink(dataHanlder.getHyperlink( | |||||
row.getSheet().getWorkbook().getCreationHelper(), t, | |||||
entity.getName(), value)); | |||||
} | |||||
}else { | |||||
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) { | |||||
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), | |||||
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)); | |||||
} | |||||
} else { | |||||
createImageCell(patriarch, entity, row, cellNum++, | createImageCell(patriarch, entity, row, cellNum++, | ||||
value == null ? "" : value.toString(), t); | value == null ? "" : value.toString(), t); | ||||
} | } | ||||
@@ -232,19 +230,16 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), | row.getSheet().getWorkbook().getCreationHelper(), obj, entity.getName(), | ||||
value)); | value)); | ||||
} | } | ||||
} | |||||
else if(entity.getType() == BaseEntityTypeConstants.DoubleType) | |||||
{ | |||||
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), | |||||
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)); | |||||
} | |||||
}else { | |||||
} else if (entity.getType() == BaseEntityTypeConstants.DoubleType) { | |||||
createDoubleCell(row, cellNum++, value == null ? "" : value.toString(), | |||||
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)); | |||||
} | |||||
} else { | |||||
createImageCell(patriarch, entity, row, cellNum++, | createImageCell(patriarch, entity, row, cellNum++, | ||||
value == null ? "" : value.toString(), obj); | value == null ? "" : value.toString(), obj); | ||||
} | } | ||||
@@ -280,7 +275,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
} | } | ||||
addStatisticsData(index, text, entity); | addStatisticsData(index, text, entity); | ||||
} | } | ||||
/** | /** | ||||
* 创建数字类型的Cell | * 创建数字类型的Cell | ||||
* | * | ||||
@@ -291,12 +286,12 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
* @param entity | * @param entity | ||||
*/ | */ | ||||
public void createDoubleCell(Row row, int index, String text, CellStyle style, | public void createDoubleCell(Row row, int index, String text, CellStyle style, | ||||
ExcelExportEntity entity) { | |||||
ExcelExportEntity entity) { | |||||
Cell cell = row.createCell(index); | Cell cell = row.createCell(index); | ||||
if(text!=null&&text.length()>0){ | |||||
cell.setCellValue(Double.parseDouble(text)); | |||||
}else{ | |||||
cell.setCellValue(-1); | |||||
if (text != null && text.length() > 0) { | |||||
cell.setCellValue(Double.parseDouble(text)); | |||||
} else { | |||||
cell.setCellValue(-1); | |||||
} | } | ||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC); | cell.setCellType(Cell.CELL_TYPE_NUMERIC); | ||||
if (style != null) { | if (style != null) { | ||||
@@ -304,8 +299,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||||
} | } | ||||
addStatisticsData(index, text, entity); | addStatisticsData(index, text, entity); | ||||
} | } | ||||
/** | /** | ||||
* 创建统计行 | * 创建统计行 | ||||
* @param styles | * @param styles | ||||
@@ -33,7 +33,7 @@ public abstract class AbstractExcelExportStyler implements IExcelExportStyler { | |||||
//间隔行 | //间隔行 | ||||
protected CellStyle stringSeptailStyle; | protected CellStyle stringSeptailStyle; | ||||
protected CellStyle stringSeptailWrapStyle; | protected CellStyle stringSeptailWrapStyle; | ||||
protected Workbook workbook; | protected Workbook workbook; | ||||
protected static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); | protected static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); | ||||
@@ -24,8 +24,8 @@ import org.apache.poi.ss.usermodel.Workbook; | |||||
* @author JueYue | * @author JueYue | ||||
* @date 2015年1月9日 下午5:55:29 | * @date 2015年1月9日 下午5:55:29 | ||||
*/ | */ | ||||
public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler implements | |||||
IExcelExportStyler { | |||||
public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler | |||||
implements IExcelExportStyler { | |||||
public ExcelExportStylerBorderImpl(Workbook workbook) { | public ExcelExportStylerBorderImpl(Workbook workbook) { | ||||
super.createStyles(workbook); | super.createStyles(workbook); | ||||
@@ -24,8 +24,8 @@ import org.apache.poi.ss.usermodel.Workbook; | |||||
* @author JueYue | * @author JueYue | ||||
* @date 2015年1月9日 下午4:54:15 | * @date 2015年1月9日 下午4:54:15 | ||||
*/ | */ | ||||
public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler implements | |||||
IExcelExportStyler { | |||||
public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler | |||||
implements IExcelExportStyler { | |||||
public ExcelExportStylerColorImpl(Workbook workbook) { | public ExcelExportStylerColorImpl(Workbook workbook) { | ||||
super.createStyles(workbook); | super.createStyles(workbook); | ||||
@@ -24,8 +24,8 @@ import org.apache.poi.ss.usermodel.Workbook; | |||||
* @author JueYue | * @author JueYue | ||||
* @date 2015年1月9日 下午5:36:08 | * @date 2015年1月9日 下午5:36:08 | ||||
*/ | */ | ||||
public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler implements | |||||
IExcelExportStyler { | |||||
public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler | |||||
implements IExcelExportStyler { | |||||
public ExcelExportStylerDefaultImpl(Workbook workbook) { | public ExcelExportStylerDefaultImpl(Workbook workbook) { | ||||
super.createStyles(workbook); | super.createStyles(workbook); | ||||
@@ -38,225 +38,219 @@ import com.google.common.collect.Lists; | |||||
* @version 1.0 | * @version 1.0 | ||||
* | * | ||||
*/ | */ | ||||
public class ExcelChartBuildService | |||||
{ | |||||
/** | |||||
* | |||||
* @param workbook | |||||
* @param graph | |||||
* @param build 通过实时数据行来重新计算图形定义 | |||||
* @param append | |||||
*/ | |||||
public static void createExcelChart(Workbook workbook,List<ExcelGraph> graphList,Boolean build,Boolean append) | |||||
{ | |||||
if(workbook!=null&&graphList!=null){ | |||||
//设定默认第一个sheet为数据项 | |||||
Sheet dataSouce=workbook.getSheetAt(0); | |||||
if(dataSouce!=null){ | |||||
buildTitle(dataSouce,graphList); | |||||
if(build){ | |||||
PoiExcelGraphDataUtil.buildGraphData(dataSouce, graphList); | |||||
} | |||||
if(append){ | |||||
buildExcelChart(dataSouce, dataSouce, graphList); | |||||
}else{ | |||||
Sheet sheet=workbook.createSheet("图形界面"); | |||||
buildExcelChart(dataSouce, sheet, graphList); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建基础图形 | |||||
* @param drawing | |||||
* @param anchor | |||||
* @param dataSourceSheet | |||||
* @param graph | |||||
*/ | |||||
private static void buildExcelChart(Drawing drawing,ClientAnchor anchor,Sheet dataSourceSheet,ExcelGraph graph){ | |||||
Chart chart = drawing.createChart(anchor); | |||||
ChartLegend legend = chart.getOrCreateLegend(); | |||||
legend.setPosition(LegendPosition.TOP_RIGHT); | |||||
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM); | |||||
public class ExcelChartBuildService { | |||||
/** | |||||
* | |||||
* @param workbook | |||||
* @param graph | |||||
* @param build 通过实时数据行来重新计算图形定义 | |||||
* @param append | |||||
*/ | |||||
public static void createExcelChart(Workbook workbook, List<ExcelGraph> graphList, | |||||
Boolean build, Boolean append) { | |||||
if (workbook != null && graphList != null) { | |||||
//设定默认第一个sheet为数据项 | |||||
Sheet dataSouce = workbook.getSheetAt(0); | |||||
if (dataSouce != null) { | |||||
buildTitle(dataSouce, graphList); | |||||
if (build) { | |||||
PoiExcelGraphDataUtil.buildGraphData(dataSouce, graphList); | |||||
} | |||||
if (append) { | |||||
buildExcelChart(dataSouce, dataSouce, graphList); | |||||
} else { | |||||
Sheet sheet = workbook.createSheet("图形界面"); | |||||
buildExcelChart(dataSouce, sheet, graphList); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建基础图形 | |||||
* @param drawing | |||||
* @param anchor | |||||
* @param dataSourceSheet | |||||
* @param graph | |||||
*/ | |||||
private static void buildExcelChart(Drawing drawing, ClientAnchor anchor, Sheet dataSourceSheet, | |||||
ExcelGraph graph) { | |||||
Chart chart = drawing.createChart(anchor); | |||||
ChartLegend legend = chart.getOrCreateLegend(); | |||||
legend.setPosition(LegendPosition.TOP_RIGHT); | |||||
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM); | |||||
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT); | ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT); | ||||
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | ||||
ExcelGraphElement categoryElement=graph.getCategory(); | |||||
ExcelGraphElement categoryElement = graph.getCategory(); | |||||
ChartDataSource categoryChart; | ChartDataSource categoryChart; | ||||
if(categoryElement!=null&&categoryElement.getElementType()==ExcelGraphElementType.StringType){ | |||||
categoryChart=DataSources.fromStringCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum())); | |||||
}else{ | |||||
categoryChart=DataSources.fromNumericCellRange(dataSourceSheet, new CellRangeAddress(categoryElement.getStartRowNum(),categoryElement.getEndRowNum(),categoryElement.getStartColNum(),categoryElement.getEndColNum())); | |||||
if (categoryElement != null | |||||
&& categoryElement.getElementType() == ExcelGraphElementType.STRING_TYPE) { | |||||
categoryChart = DataSources.fromStringCellRange(dataSourceSheet, | |||||
new CellRangeAddress(categoryElement.getStartRowNum(), | |||||
categoryElement.getEndRowNum(), categoryElement.getStartColNum(), | |||||
categoryElement.getEndColNum())); | |||||
} else { | |||||
categoryChart = DataSources.fromNumericCellRange(dataSourceSheet, | |||||
new CellRangeAddress(categoryElement.getStartRowNum(), | |||||
categoryElement.getEndRowNum(), categoryElement.getStartColNum(), | |||||
categoryElement.getEndColNum())); | |||||
} | |||||
List<ExcelGraphElement> valueList = graph.getValueList(); | |||||
List<ChartDataSource<Number>> chartValueList = Lists.newArrayList(); | |||||
if (valueList != null && valueList.size() > 0) { | |||||
for (ExcelGraphElement ele : valueList) { | |||||
ChartDataSource<Number> source = DataSources.fromNumericCellRange(dataSourceSheet, | |||||
new CellRangeAddress(ele.getStartRowNum(), ele.getEndRowNum(), | |||||
ele.getStartColNum(), ele.getEndColNum())); | |||||
chartValueList.add(source); | |||||
} | |||||
} | |||||
if (graph.getGraphType() == ExcelGraphType.LINE_CHART) { | |||||
LineChartData data = chart.getChartDataFactory().createLineChartData(); | |||||
buildLineChartData(data, categoryChart, chartValueList, graph.getTitle()); | |||||
chart.plot(data, bottomAxis, leftAxis); | |||||
} else { | |||||
ScatterChartData data = chart.getChartDataFactory().createScatterChartData(); | |||||
buildScatterChartData(data, categoryChart, chartValueList, graph.getTitle()); | |||||
chart.plot(data, bottomAxis, leftAxis); | |||||
} | |||||
} | |||||
/** | |||||
* 构建多个图形对象 | |||||
* @param dataSourceSheet | |||||
* @param tragetSheet | |||||
* @param graphList | |||||
*/ | |||||
private static void buildExcelChart(Sheet dataSourceSheet, Sheet tragetSheet, | |||||
List<ExcelGraph> graphList) { | |||||
int len = graphList.size(); | |||||
if (len == 1) { | |||||
buildExcelChart(dataSourceSheet, tragetSheet, graphList.get(0)); | |||||
} else { | |||||
int drawStart = 0; | |||||
int drawEnd = 20; | |||||
Drawing drawing = tragetSheet.createDrawingPatriarch(); | |||||
for (int i = 0; i < len; i++) { | |||||
ExcelGraph graph = graphList.get(i); | |||||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, drawStart, 15, drawEnd); | |||||
buildExcelChart(drawing, anchor, dataSourceSheet, graph); | |||||
drawStart = drawStart + drawEnd; | |||||
drawEnd = drawEnd + drawEnd; | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建图形对象 | |||||
* @param workbook | |||||
* @param dataSourceSheet | |||||
* @param tragetSheet | |||||
* @param graph | |||||
*/ | |||||
private static void buildExcelChart(Sheet dataSourceSheet, Sheet tragetSheet, | |||||
ExcelGraph graph) { | |||||
Drawing drawing = tragetSheet.createDrawingPatriarch(); | |||||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 0, 15, 20); | |||||
buildExcelChart(drawing, anchor, dataSourceSheet, graph); | |||||
} | |||||
/** | |||||
* 构建Title | |||||
* @param sheet | |||||
* @param graph | |||||
*/ | |||||
private static void buildTitle(Sheet sheet, ExcelGraph graph) { | |||||
int cellTitleLen = graph.getTitleCell().size(); | |||||
int titleLen = graph.getTitle().size(); | |||||
if (titleLen > 0) { | |||||
} else { | |||||
for (int i = 0; i < cellTitleLen; i++) { | |||||
ExcelTitleCell titleCell = graph.getTitleCell().get(i); | |||||
if (titleCell != null) { | |||||
graph.getTitle().add( | |||||
PoiCellUtil.getCellValue(sheet, titleCell.getRow(), titleCell.getCol())); | |||||
} | |||||
} | |||||
} | } | ||||
List<ExcelGraphElement> valueList=graph.getValueList(); | |||||
List<ChartDataSource<Number>> chartValueList=Lists.newArrayList(); | |||||
if(valueList!=null&&valueList.size()>0){ | |||||
for(ExcelGraphElement ele:valueList){ | |||||
ChartDataSource<Number> source=DataSources.fromNumericCellRange(dataSourceSheet, new CellRangeAddress(ele.getStartRowNum(),ele.getEndRowNum(),ele.getStartColNum(),ele.getEndColNum())); | |||||
chartValueList.add(source); | |||||
} | |||||
} | |||||
/** | |||||
* 构建Title | |||||
* @param sheet | |||||
* @param graphList | |||||
*/ | |||||
private static void buildTitle(Sheet sheet, List<ExcelGraph> graphList) { | |||||
if (graphList != null && graphList.size() > 0) { | |||||
for (ExcelGraph graph : graphList) { | |||||
if (graph != null) { | |||||
buildTitle(sheet, graph); | |||||
} | |||||
} | |||||
} | } | ||||
if(graph.getGraphType()==ExcelGraphType.LineChart){ | |||||
LineChartData data = chart.getChartDataFactory().createLineChartData(); | |||||
buildLineChartData(data, categoryChart, chartValueList, graph.getTitle()); | |||||
chart.plot(data, bottomAxis, leftAxis); | |||||
} | |||||
else | |||||
{ | |||||
ScatterChartData data=chart.getChartDataFactory().createScatterChartData(); | |||||
buildScatterChartData(data, categoryChart, chartValueList,graph.getTitle()); | |||||
chart.plot(data, bottomAxis, leftAxis); | |||||
} | |||||
} | |||||
/** | |||||
* 构建多个图形对象 | |||||
* @param dataSourceSheet | |||||
* @param tragetSheet | |||||
* @param graphList | |||||
*/ | |||||
private static void buildExcelChart(Sheet dataSourceSheet,Sheet tragetSheet,List<ExcelGraph> graphList){ | |||||
int len=graphList.size(); | |||||
if(len==1) | |||||
{ | |||||
buildExcelChart(dataSourceSheet, tragetSheet, graphList.get(0)); | |||||
} | |||||
else | |||||
{ | |||||
int drawStart=0; | |||||
int drawEnd=20; | |||||
Drawing drawing = tragetSheet.createDrawingPatriarch(); | |||||
for(int i=0;i<len;i++){ | |||||
ExcelGraph graph=graphList.get(i); | |||||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, drawStart, 15, drawEnd); | |||||
buildExcelChart(drawing, anchor, dataSourceSheet, graph); | |||||
drawStart=drawStart+drawEnd; | |||||
drawEnd=drawEnd+drawEnd; | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建图形对象 | |||||
* @param workbook | |||||
* @param dataSourceSheet | |||||
* @param tragetSheet | |||||
* @param graph | |||||
*/ | |||||
private static void buildExcelChart(Sheet dataSourceSheet,Sheet tragetSheet,ExcelGraph graph){ | |||||
Drawing drawing = tragetSheet.createDrawingPatriarch(); | |||||
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 0, 15, 20); | |||||
buildExcelChart(drawing, anchor, dataSourceSheet, graph); | |||||
} | |||||
/** | |||||
* 构建Title | |||||
* @param sheet | |||||
* @param graph | |||||
*/ | |||||
private static void buildTitle(Sheet sheet,ExcelGraph graph){ | |||||
int cellTitleLen=graph.getTitleCell().size(); | |||||
int titleLen=graph.getTitle().size(); | |||||
if(titleLen>0){ | |||||
}else{ | |||||
for(int i=0;i<cellTitleLen;i++){ | |||||
ExcelTitleCell titleCell=graph.getTitleCell().get(i); | |||||
if(titleCell!=null){ | |||||
graph.getTitle().add(PoiCellUtil.getCellValue(sheet,titleCell.getRow(),titleCell.getCol())); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建Title | |||||
* @param sheet | |||||
* @param graphList | |||||
*/ | |||||
private static void buildTitle(Sheet sheet,List<ExcelGraph> graphList){ | |||||
if(graphList!=null&&graphList.size()>0){ | |||||
for(ExcelGraph graph:graphList){ | |||||
if(graph!=null) | |||||
{ | |||||
buildTitle(sheet, graph); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* | |||||
* @param data | |||||
* @param categoryChart | |||||
* @param chartValueList | |||||
* @param title | |||||
*/ | |||||
private static void buildLineChartData(LineChartData data,ChartDataSource categoryChart,List<ChartDataSource<Number>> chartValueList,List<String> title){ | |||||
if(chartValueList.size()==title.size()) | |||||
{ | |||||
int len=title.size(); | |||||
for(int i=0;i<len;i++){ | |||||
data.addSerie(categoryChart, chartValueList.get(i)).setTitle(title.get(i)); | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
int i=0; | |||||
for(ChartDataSource<Number> source:chartValueList){ | |||||
String _title=title.get(i); | |||||
if(StringUtils.isNotBlank(_title)){ | |||||
data.addSerie(categoryChart, source).setTitle(_title); | |||||
}else{ | |||||
data.addSerie(categoryChart, source); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* | |||||
* @param data | |||||
* @param categoryChart | |||||
* @param chartValueList | |||||
* @param title | |||||
*/ | |||||
private static void buildScatterChartData(ScatterChartData data,ChartDataSource categoryChart,List<ChartDataSource<Number>> chartValueList,List<String> title){ | |||||
if(chartValueList.size()==title.size()) | |||||
{ | |||||
int len=title.size(); | |||||
for(int i=0;i<len;i++){ | |||||
data.addSerie(categoryChart, chartValueList.get(i)).setTitle(title.get(i)); | |||||
} | |||||
} | |||||
else | |||||
{ | |||||
int i=0; | |||||
for(ChartDataSource<Number> source:chartValueList){ | |||||
String _title=title.get(i); | |||||
if(StringUtils.isNotBlank(_title)){ | |||||
data.addSerie(categoryChart, source).setTitle(_title); | |||||
}else{ | |||||
data.addSerie(categoryChart, source); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* | |||||
* @param data | |||||
* @param categoryChart | |||||
* @param chartValueList | |||||
* @param title | |||||
*/ | |||||
private static void buildLineChartData(LineChartData data, ChartDataSource categoryChart, | |||||
List<ChartDataSource<Number>> chartValueList, | |||||
List<String> title) { | |||||
if (chartValueList.size() == title.size()) { | |||||
int len = title.size(); | |||||
for (int i = 0; i < len; i++) { | |||||
data.addSerie(categoryChart, chartValueList.get(i)).setTitle(title.get(i)); | |||||
} | |||||
} else { | |||||
int i = 0; | |||||
for (ChartDataSource<Number> source : chartValueList) { | |||||
String _title = title.get(i); | |||||
if (StringUtils.isNotBlank(_title)) { | |||||
data.addSerie(categoryChart, source).setTitle(_title); | |||||
} else { | |||||
data.addSerie(categoryChart, source); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* | |||||
* @param data | |||||
* @param categoryChart | |||||
* @param chartValueList | |||||
* @param title | |||||
*/ | |||||
private static void buildScatterChartData(ScatterChartData data, ChartDataSource categoryChart, | |||||
List<ChartDataSource<Number>> chartValueList, | |||||
List<String> title) { | |||||
if (chartValueList.size() == title.size()) { | |||||
int len = title.size(); | |||||
for (int i = 0; i < len; i++) { | |||||
data.addSerie(categoryChart, chartValueList.get(i)).setTitle(title.get(i)); | |||||
} | |||||
} else { | |||||
int i = 0; | |||||
for (ChartDataSource<Number> source : chartValueList) { | |||||
String _title = title.get(i); | |||||
if (StringUtils.isNotBlank(_title)) { | |||||
data.addSerie(categoryChart, source).setTitle(_title); | |||||
} else { | |||||
data.addSerie(categoryChart, source); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } |
@@ -9,8 +9,7 @@ package org.jeecgframework.poi.excel.graph.constant; | |||||
* @version 1.0 | * @version 1.0 | ||||
* 定义元素类型 | * 定义元素类型 | ||||
*/ | */ | ||||
public interface ExcelGraphElementType | |||||
{ | |||||
public static final Integer StringType=1; | |||||
public static final Integer NumericType=2; | |||||
public interface ExcelGraphElementType { | |||||
public static final Integer STRING_TYPE = 1; | |||||
public static final Integer NUMERIC_TYPE = 2; | |||||
} | } |
@@ -9,9 +9,8 @@ package org.jeecgframework.poi.excel.graph.constant; | |||||
* @version 1.0 | * @version 1.0 | ||||
* 定义图形类型 | * 定义图形类型 | ||||
*/ | */ | ||||
public interface ExcelGraphType | |||||
{ | |||||
public static final Integer LineChart=1; | |||||
public static final Integer ScatterChart=2; | |||||
public interface ExcelGraphType { | |||||
public static final Integer LINE_CHART = 1; | |||||
public static final Integer SCATTER_CHART = 2; | |||||
} | } |
@@ -12,11 +12,14 @@ import java.util.List; | |||||
* @see com.dawnpro.core.export.excel.model.ExcelGraph | * @see com.dawnpro.core.export.excel.model.ExcelGraph | ||||
* | * | ||||
*/ | */ | ||||
public interface ExcelGraph | |||||
{ | |||||
public ExcelGraphElement getCategory(); | |||||
public List<ExcelGraphElement> getValueList(); | |||||
public Integer getGraphType(); | |||||
public List<ExcelTitleCell> getTitleCell(); | |||||
public List<String> getTitle(); | |||||
public interface ExcelGraph { | |||||
public ExcelGraphElement getCategory(); | |||||
public List<ExcelGraphElement> getValueList(); | |||||
public Integer getGraphType(); | |||||
public List<ExcelTitleCell> getTitleCell(); | |||||
public List<String> getTitle(); | |||||
} | } |
@@ -15,56 +15,51 @@ import com.google.common.collect.Lists; | |||||
* @version 1.0 | * @version 1.0 | ||||
* | * | ||||
*/ | */ | ||||
public class ExcelGraphDefined implements ExcelGraph | |||||
{ | |||||
private ExcelGraphElement category; | |||||
public List<ExcelGraphElement> valueList=Lists.newArrayList(); | |||||
public List<ExcelTitleCell> titleCell=Lists.newArrayList(); | |||||
private Integer graphType=ExcelGraphType.LineChart; | |||||
public List<String> title=Lists.newArrayList(); | |||||
public ExcelGraphElement getCategory() | |||||
{ | |||||
return category; | |||||
} | |||||
public void setCategory(ExcelGraphElement category) | |||||
{ | |||||
this.category = category; | |||||
} | |||||
public List<ExcelGraphElement> getValueList() | |||||
{ | |||||
return valueList; | |||||
} | |||||
public void setValueList(List<ExcelGraphElement> valueList) | |||||
{ | |||||
this.valueList = valueList; | |||||
} | |||||
public class ExcelGraphDefined implements ExcelGraph { | |||||
private ExcelGraphElement category; | |||||
public List<ExcelGraphElement> valueList = Lists.newArrayList(); | |||||
public List<ExcelTitleCell> titleCell = Lists.newArrayList(); | |||||
private Integer graphType = ExcelGraphType.LINE_CHART; | |||||
public List<String> title = Lists.newArrayList(); | |||||
public ExcelGraphElement getCategory() { | |||||
return category; | |||||
} | |||||
public void setCategory(ExcelGraphElement category) { | |||||
this.category = category; | |||||
} | |||||
public List<ExcelGraphElement> getValueList() { | |||||
return valueList; | |||||
} | |||||
public void setValueList(List<ExcelGraphElement> valueList) { | |||||
this.valueList = valueList; | |||||
} | |||||
public Integer getGraphType() { | |||||
return graphType; | |||||
} | |||||
public void setGraphType(Integer graphType) { | |||||
this.graphType = graphType; | |||||
} | |||||
public List<ExcelTitleCell> getTitleCell() { | |||||
return titleCell; | |||||
} | |||||
public void setTitleCell(List<ExcelTitleCell> titleCell) { | |||||
this.titleCell = titleCell; | |||||
} | |||||
public List<String> getTitle() { | |||||
return title; | |||||
} | |||||
public void setTitle(List<String> title) { | |||||
this.title = title; | |||||
} | |||||
public Integer getGraphType() | |||||
{ | |||||
return graphType; | |||||
} | |||||
public void setGraphType(Integer graphType) | |||||
{ | |||||
this.graphType = graphType; | |||||
} | |||||
public List<ExcelTitleCell> getTitleCell() | |||||
{ | |||||
return titleCell; | |||||
} | |||||
public void setTitleCell(List<ExcelTitleCell> titleCell) | |||||
{ | |||||
this.titleCell = titleCell; | |||||
} | |||||
public List<String> getTitle() | |||||
{ | |||||
return title; | |||||
} | |||||
public void setTitle(List<String> title) | |||||
{ | |||||
this.title = title; | |||||
} | |||||
} | } |
@@ -5,60 +5,56 @@ package org.jeecgframework.poi.excel.graph.entity; | |||||
import org.jeecgframework.poi.excel.graph.constant.ExcelGraphElementType; | import org.jeecgframework.poi.excel.graph.constant.ExcelGraphElementType; | ||||
/** | /** | ||||
* @author xfworld | * @author xfworld | ||||
* @since 2015-12-30 | * @since 2015-12-30 | ||||
* @version 1.0 | * @version 1.0 | ||||
* | * | ||||
*/ | */ | ||||
public class ExcelGraphElement | |||||
{ | |||||
private Integer startRowNum; | |||||
private Integer endRowNum; | |||||
private Integer startColNum; | |||||
private Integer endColNum; | |||||
private Integer elementType=ExcelGraphElementType.StringType; | |||||
public Integer getStartRowNum() | |||||
{ | |||||
return startRowNum; | |||||
} | |||||
public void setStartRowNum(Integer startRowNum) | |||||
{ | |||||
this.startRowNum = startRowNum; | |||||
} | |||||
public Integer getEndRowNum() | |||||
{ | |||||
return endRowNum; | |||||
} | |||||
public void setEndRowNum(Integer endRowNum) | |||||
{ | |||||
this.endRowNum = endRowNum; | |||||
} | |||||
public Integer getStartColNum() | |||||
{ | |||||
return startColNum; | |||||
} | |||||
public void setStartColNum(Integer startColNum) | |||||
{ | |||||
this.startColNum = startColNum; | |||||
} | |||||
public Integer getEndColNum() | |||||
{ | |||||
return endColNum; | |||||
} | |||||
public void setEndColNum(Integer endColNum) | |||||
{ | |||||
this.endColNum = endColNum; | |||||
} | |||||
public Integer getElementType() | |||||
{ | |||||
return elementType; | |||||
} | |||||
public void setElementType(Integer elementType) | |||||
{ | |||||
this.elementType = elementType; | |||||
} | |||||
public class ExcelGraphElement { | |||||
private Integer startRowNum; | |||||
private Integer endRowNum; | |||||
private Integer startColNum; | |||||
private Integer endColNum; | |||||
private Integer elementType = ExcelGraphElementType.STRING_TYPE; | |||||
public Integer getStartRowNum() { | |||||
return startRowNum; | |||||
} | |||||
public void setStartRowNum(Integer startRowNum) { | |||||
this.startRowNum = startRowNum; | |||||
} | |||||
public Integer getEndRowNum() { | |||||
return endRowNum; | |||||
} | |||||
public void setEndRowNum(Integer endRowNum) { | |||||
this.endRowNum = endRowNum; | |||||
} | |||||
public Integer getStartColNum() { | |||||
return startColNum; | |||||
} | |||||
public void setStartColNum(Integer startColNum) { | |||||
this.startColNum = startColNum; | |||||
} | |||||
public Integer getEndColNum() { | |||||
return endColNum; | |||||
} | |||||
public void setEndColNum(Integer endColNum) { | |||||
this.endColNum = endColNum; | |||||
} | |||||
public Integer getElementType() { | |||||
return elementType; | |||||
} | |||||
public void setElementType(Integer elementType) { | |||||
this.elementType = elementType; | |||||
} | |||||
} | } |
@@ -9,36 +9,33 @@ package org.jeecgframework.poi.excel.graph.entity; | |||||
* @version 1.0 | * @version 1.0 | ||||
* | * | ||||
*/ | */ | ||||
public class ExcelTitleCell | |||||
{ | |||||
private Integer row; | |||||
private Integer col; | |||||
public ExcelTitleCell(){ | |||||
} | |||||
public ExcelTitleCell(Integer row,Integer col){ | |||||
this.row=row; | |||||
this.col=col; | |||||
} | |||||
public Integer getRow() | |||||
{ | |||||
return row; | |||||
} | |||||
public void setRow(Integer row) | |||||
{ | |||||
this.row = row; | |||||
} | |||||
public Integer getCol() | |||||
{ | |||||
return col; | |||||
} | |||||
public void setCol(Integer col) | |||||
{ | |||||
this.col = col; | |||||
} | |||||
public class ExcelTitleCell { | |||||
private Integer row; | |||||
private Integer col; | |||||
public ExcelTitleCell() { | |||||
} | |||||
public ExcelTitleCell(Integer row, Integer col) { | |||||
this.row = row; | |||||
this.col = col; | |||||
} | |||||
public Integer getRow() { | |||||
return row; | |||||
} | |||||
public void setRow(Integer row) { | |||||
this.row = row; | |||||
} | |||||
public Integer getCol() { | |||||
return col; | |||||
} | |||||
public void setCol(Integer col) { | |||||
this.col = col; | |||||
} | |||||
} | } |
@@ -35,31 +35,32 @@ import org.slf4j.LoggerFactory; | |||||
*/ | */ | ||||
public class ExcelToHtmlServer { | public class ExcelToHtmlServer { | ||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExcelToHtmlServer.class); | |||||
private static final Logger LOGGER = LoggerFactory | |||||
.getLogger(ExcelToHtmlServer.class); | |||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy_MM_dd"); | |||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy_MM_dd"); | |||||
private String today; | |||||
private String today; | |||||
private Workbook wb; | |||||
private int sheetNum; | |||||
private int cssRandom; | |||||
private Workbook wb; | |||||
private int sheetNum; | |||||
private int cssRandom; | |||||
/*是不是完成界面*/ | /*是不是完成界面*/ | ||||
private boolean completeHTML; | |||||
private Formatter out; | |||||
private boolean completeHTML; | |||||
private Formatter out; | |||||
/*已经完成范围处理*/ | /*已经完成范围处理*/ | ||||
private boolean gotBounds; | |||||
private int firstColumn; | |||||
private int endColumn; | |||||
private String imageCachePath; | |||||
private static final String COL_HEAD_CLASS = "colHeader"; | |||||
private boolean gotBounds; | |||||
private int firstColumn; | |||||
private int endColumn; | |||||
private String imageCachePath; | |||||
private static final String COL_HEAD_CLASS = "colHeader"; | |||||
//private static final String ROW_HEAD_CLASS = "rowHeader"; | //private static final String ROW_HEAD_CLASS = "rowHeader"; | ||||
private static final String DEFAULTS_CLASS = "excelDefaults"; | |||||
private static final String DEFAULTS_CLASS = "excelDefaults"; | |||||
//图片缓存 | //图片缓存 | ||||
private Map<String, PictureData> pictures = new HashMap<String, PictureData>(); | |||||
private Map<String, PictureData> pictures = new HashMap<String, PictureData>(); | |||||
public ExcelToHtmlServer(ExcelToHtmlParams params) { | public ExcelToHtmlServer(ExcelToHtmlParams params) { | ||||
this.wb = params.getWb(); | this.wb = params.getWb(); | ||||
@@ -37,8 +37,8 @@ public class CellValueHelper { | |||||
is07 = true; | is07 = true; | ||||
cacheFontInfo(wb); | cacheFontInfo(wb); | ||||
} else | } else | ||||
throw new IllegalArgumentException("unknown workbook type: " | |||||
+ wb.getClass().getSimpleName()); | |||||
throw new IllegalArgumentException( | |||||
"unknown workbook type: " + wb.getClass().getSimpleName()); | |||||
} | } | ||||
/** | /** | ||||
@@ -91,11 +91,11 @@ public class CellValueHelper { | |||||
sb.append("'>"); | sb.append("'>"); | ||||
currentIndex = rich.getIndexOfFormattingRun(i); | currentIndex = rich.getIndexOfFormattingRun(i); | ||||
if (i < nums - 1) { | if (i < nums - 1) { | ||||
sb.append(XmlEscapers.xmlContentEscaper().escape( | |||||
text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1)))); | |||||
sb.append(XmlEscapers.xmlContentEscaper() | |||||
.escape(text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1)))); | |||||
} else { | } else { | ||||
sb.append(XmlEscapers.xmlContentEscaper().escape( | |||||
text.substring(currentIndex, text.length()))); | |||||
sb.append(XmlEscapers.xmlContentEscaper() | |||||
.escape(text.substring(currentIndex, text.length()))); | |||||
} | } | ||||
sb.append("</span>"); | sb.append("</span>"); | ||||
} | } | ||||
@@ -122,10 +122,10 @@ public class CellValueHelper { | |||||
} catch (Exception e) { | } catch (Exception e) { | ||||
} | } | ||||
sb.append(">"); | sb.append(">"); | ||||
currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich | |||||
.getIndexOfFormattingRun(i); | |||||
sb.append(XmlEscapers.xmlContentEscaper().escape( | |||||
text.substring(lastIndex, currentIndex))); | |||||
currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() | |||||
: rich.getIndexOfFormattingRun(i); | |||||
sb.append( | |||||
XmlEscapers.xmlContentEscaper().escape(text.substring(lastIndex, currentIndex))); | |||||
sb.append("</span>"); | sb.append("</span>"); | ||||
lastIndex = currentIndex; | lastIndex = currentIndex; | ||||
} | } | ||||
@@ -133,8 +133,8 @@ public class CellValueHelper { | |||||
} | } | ||||
private String getFontIndex(XSSFFont font) { | private String getFontIndex(XSSFFont font) { | ||||
return fontCache.get(font.getBoldweight() + "_" + font.getItalic() + "_" | |||||
+ font.getFontName() + "_" + font.getFontHeightInPoints() + "_" | |||||
+ font.getColor()); | |||||
return fontCache | |||||
.get(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName() + "_" | |||||
+ font.getFontHeightInPoints() + "_" + font.getColor()); | |||||
} | } | ||||
} | } |
@@ -46,8 +46,8 @@ public class MergedRegionHelper { | |||||
endCol = (endCol + 1) * 26 + (strArr[1].charAt(1) - 65); | endCol = (endCol + 1) * 26 + (strArr[1].charAt(1) - 65); | ||||
} | } | ||||
int endRol = Integer.valueOf(strArr[1].substring(strArr[1].charAt(1) >= 65 ? 2 : 1)); | int endRol = Integer.valueOf(strArr[1].substring(strArr[1].charAt(1) >= 65 ? 2 : 1)); | ||||
mergedCache.put(startRol + "_" + startCol, new Integer[] { endRol - startRol + 1, | |||||
endCol - startCol + 1 }); | |||||
mergedCache.put(startRol + "_" + startCol, | |||||
new Integer[] { endRol - startRol + 1, endCol - startCol + 1 }); | |||||
for (int i = startRol; i <= endRol; i++) { | for (int i = startRol; i <= endRol; i++) { | ||||
for (int j = startCol; j <= endCol; j++) { | for (int j = startCol; j <= endCol; j++) { | ||||
notNeedCread.add(i + "_" + j); | notNeedCread.add(i + "_" + j); | ||||
@@ -47,19 +47,12 @@ public class StylerHelper { | |||||
private static final String DEFAULTS_CLASS = "excelDefaults"; | private static final String DEFAULTS_CLASS = "excelDefaults"; | ||||
private static final Map<Short, String> ALIGN = PoiPublicUtil | |||||
.mapFor(ALIGN_LEFT, "left", | |||||
ALIGN_CENTER, "center", | |||||
ALIGN_RIGHT, "right", | |||||
ALIGN_FILL, "left", | |||||
ALIGN_JUSTIFY, "left", | |||||
ALIGN_CENTER_SELECTION, | |||||
"center"); | |||||
private static final Map<Short, String> VERTICAL_ALIGN = PoiPublicUtil.mapFor( | |||||
VERTICAL_BOTTOM, "bottom", | |||||
VERTICAL_CENTER, "middle", | |||||
VERTICAL_TOP, "top"); | |||||
private static final Map<Short, String> ALIGN = PoiPublicUtil.mapFor(ALIGN_LEFT, | |||||
"left", ALIGN_CENTER, "center", ALIGN_RIGHT, "right", ALIGN_FILL, "left", ALIGN_JUSTIFY, | |||||
"left", ALIGN_CENTER_SELECTION, "center"); | |||||
private static final Map<Short, String> VERTICAL_ALIGN = PoiPublicUtil | |||||
.mapFor(VERTICAL_BOTTOM, "bottom", VERTICAL_CENTER, "middle", VERTICAL_TOP, "top"); | |||||
private Formatter out; | private Formatter out; | ||||
@@ -80,8 +73,8 @@ public class StylerHelper { | |||||
else if (wb instanceof XSSFWorkbook) | else if (wb instanceof XSSFWorkbook) | ||||
helper = new XSSFHtmlHelper((XSSFWorkbook) wb); | helper = new XSSFHtmlHelper((XSSFWorkbook) wb); | ||||
else | else | ||||
throw new IllegalArgumentException("unknown workbook type: " | |||||
+ wb.getClass().getSimpleName()); | |||||
throw new IllegalArgumentException( | |||||
"unknown workbook type: " + wb.getClass().getSimpleName()); | |||||
printInlineStyle(wb); | printInlineStyle(wb); | ||||
} | } | ||||
@@ -127,8 +120,8 @@ public class StylerHelper { | |||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
Formatter formatter = new Formatter(sb); | Formatter formatter = new Formatter(sb); | ||||
try { | try { | ||||
in = new BufferedReader(new InputStreamReader( | |||||
StylerHelper.class.getResourceAsStream("excelStyle.css"))); | |||||
in = new BufferedReader( | |||||
new InputStreamReader(StylerHelper.class.getResourceAsStream("excelStyle.css"))); | |||||
String line; | String line; | ||||
while ((line = in.readLine()) != null) { | while ((line = in.readLine()) != null) { | ||||
formatter.format("%s%n", line); | formatter.format("%s%n", line); | ||||
@@ -48,9 +48,9 @@ import org.slf4j.LoggerFactory; | |||||
*/ | */ | ||||
public class CellValueServer { | public class CellValueServer { | ||||
private static final Logger LOGGER = LoggerFactory.getLogger(CellValueServer.class); | |||||
private static final Logger LOGGER = LoggerFactory.getLogger(CellValueServer.class); | |||||
private List<String> hanlderList = null; | |||||
private List<String> hanlderList = null; | |||||
/** | /** | ||||
* 获取单元格内的值 | * 获取单元格内的值 | ||||
@@ -243,7 +243,7 @@ public class CellValueServer { | |||||
private Object getValueByType(String xclass, Object result, ExcelImportEntity entity) { | private Object getValueByType(String xclass, Object result, ExcelImportEntity entity) { | ||||
try { | try { | ||||
//过滤空和空字符串,如果基本类型null会在上层抛出,这里就不处理了 | //过滤空和空字符串,如果基本类型null会在上层抛出,这里就不处理了 | ||||
if(result == null || StringUtils.isBlank(result.toString())){ | |||||
if (result == null || StringUtils.isBlank(result.toString())) { | |||||
return null; | return null; | ||||
} | } | ||||
if ("class java.util.Date".equals(xclass)) { | if ("class java.util.Date".equals(xclass)) { | ||||
@@ -69,15 +69,15 @@ import org.slf4j.LoggerFactory; | |||||
@SuppressWarnings({ "rawtypes", "unchecked", "hiding" }) | @SuppressWarnings({ "rawtypes", "unchecked", "hiding" }) | ||||
public class ExcelImportServer extends ImportBaseService { | public class ExcelImportServer extends ImportBaseService { | ||||
private final static Logger LOGGER = LoggerFactory.getLogger(ExcelImportServer.class); | |||||
private final static Logger LOGGER = LoggerFactory.getLogger(ExcelImportServer.class); | |||||
private CellValueServer cellValueServer; | |||||
private CellValueServer cellValueServer; | |||||
private boolean verfiyFail = false; | |||||
private boolean verfiyFail = false; | |||||
/** | /** | ||||
* 异常数据styler | * 异常数据styler | ||||
*/ | */ | ||||
private CellStyle errorCellStyle; | |||||
private CellStyle errorCellStyle; | |||||
public ExcelImportServer() { | public ExcelImportServer() { | ||||
this.cellValueServer = new CellValueServer(); | this.cellValueServer = new CellValueServer(); | ||||
@@ -195,7 +195,7 @@ public class ExcelImportServer extends ImportBaseService { | |||||
rows.next(); | rows.next(); | ||||
} | } | ||||
Map<Integer, String> titlemap = getTitleMap(rows, params, excelCollection); | Map<Integer, String> titlemap = getTitleMap(rows, params, excelCollection); | ||||
checkIsValidTemplate(titlemap, excelParams, params,excelCollection); | |||||
checkIsValidTemplate(titlemap, excelParams, params, excelCollection); | |||||
Row row = null; | Row row = null; | ||||
Object object = null; | Object object = null; | ||||
String picId; | String picId; | ||||
@@ -415,31 +415,36 @@ public class ExcelImportServer extends ImportBaseService { | |||||
* @param params | * @param params | ||||
* @param excelCollection | * @param excelCollection | ||||
*/ | */ | ||||
private void checkIsValidTemplate(Map<Integer, String> titlemap, Map<String, ExcelImportEntity> excelParams, ImportParams params, List<ExcelCollectionParams> excelCollection) { | |||||
if(params.getImportFields() != null){ | |||||
for (int i = 0 ,le = params.getImportFields().length; i < le; i++) { | |||||
if(!titlemap.containsValue(params.getImportFields()[i])){ | |||||
throw new ExcelImportException(ExcelImportEnum.IS_NOT_A_VALID_TEMPLATE); | |||||
private void checkIsValidTemplate(Map<Integer, String> titlemap, | |||||
Map<String, ExcelImportEntity> excelParams, | |||||
ImportParams params, | |||||
List<ExcelCollectionParams> excelCollection) { | |||||
if (params.getImportFields() != null) { | |||||
for (int i = 0, le = params.getImportFields().length; i < le; i++) { | |||||
if (!titlemap.containsValue(params.getImportFields()[i])) { | |||||
throw new ExcelImportException(ExcelImportEnum.IS_NOT_A_VALID_TEMPLATE); | |||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
Collection<ExcelImportEntity> collection = excelParams.values(); | |||||
for (ExcelImportEntity excelImportEntity : collection) { | |||||
if(excelImportEntity.isImportField() && !titlemap.containsValue(excelImportEntity.getName())){ | |||||
throw new ExcelImportException(ExcelImportEnum.IS_NOT_A_VALID_TEMPLATE); | |||||
} | |||||
} | |||||
for (int i = 0, le = excelCollection.size(); i < le; i++) { | |||||
ExcelCollectionParams collectionparams = excelCollection.get(i); | |||||
collection = collectionparams.getExcelParams().values(); | |||||
for (ExcelImportEntity excelImportEntity : collection) { | |||||
if(excelImportEntity.isImportField() && !titlemap.containsValue(collectionparams.getExcelName()+"_"+excelImportEntity.getName())){ | |||||
throw new ExcelImportException(ExcelImportEnum.IS_NOT_A_VALID_TEMPLATE); | |||||
} | |||||
} | |||||
} | |||||
Collection<ExcelImportEntity> collection = excelParams.values(); | |||||
for (ExcelImportEntity excelImportEntity : collection) { | |||||
if (excelImportEntity.isImportField() | |||||
&& !titlemap.containsValue(excelImportEntity.getName())) { | |||||
throw new ExcelImportException(ExcelImportEnum.IS_NOT_A_VALID_TEMPLATE); | |||||
} | |||||
} | |||||
for (int i = 0, le = excelCollection.size(); i < le; i++) { | |||||
ExcelCollectionParams collectionparams = excelCollection.get(i); | |||||
collection = collectionparams.getExcelParams().values(); | |||||
for (ExcelImportEntity excelImportEntity : collection) { | |||||
if (excelImportEntity.isImportField() && !titlemap.containsValue( | |||||
collectionparams.getExcelName() + "_" + excelImportEntity.getName())) { | |||||
throw new ExcelImportException(ExcelImportEnum.IS_NOT_A_VALID_TEMPLATE); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -82,8 +82,8 @@ public class SaxReadExcel { | |||||
} | } | ||||
} | } | ||||
private XMLReader fetchSheetParser(SharedStringsTable sst, ISaxRowRead rowRead) | |||||
throws SAXException { | |||||
private XMLReader fetchSheetParser(SharedStringsTable sst, | |||||
ISaxRowRead rowRead) throws SAXException { | |||||
XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); | XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); | ||||
ContentHandler handler = new SheetHandler(sst, rowRead); | ContentHandler handler = new SheetHandler(sst, rowRead); | ||||
parser.setContentHandler(handler); | parser.setContentHandler(handler); | ||||
@@ -59,8 +59,8 @@ public class SheetHandler extends DefaultHandler { | |||||
} | } | ||||
@Override | @Override | ||||
public void startElement(String uri, String localName, String name, Attributes attributes) | |||||
throws SAXException { | |||||
public void startElement(String uri, String localName, String name, | |||||
Attributes attributes) throws SAXException { | |||||
// 置空 | // 置空 | ||||
lastContents = ""; | lastContents = ""; | ||||
// c => 单元格 | // c => 单元格 | ||||
@@ -26,6 +26,7 @@ public interface ISaxRowRead { | |||||
* @return | * @return | ||||
*/ | */ | ||||
public <T> List<T> getList(); | public <T> List<T> getList(); | ||||
/** | /** | ||||
* 解析数据 | * 解析数据 | ||||
* @param index | * @param index | ||||
@@ -33,5 +34,4 @@ public interface ISaxRowRead { | |||||
*/ | */ | ||||
public void parse(int index, List<SaxReadCellEntity> datas); | public void parse(int index, List<SaxReadCellEntity> datas); | ||||
} | } |
@@ -49,7 +49,7 @@ import com.google.common.collect.Lists; | |||||
public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | ||||
private static final Logger LOGGER = LoggerFactory | private static final Logger LOGGER = LoggerFactory | ||||
.getLogger(SaxRowRead.class); | |||||
.getLogger(SaxRowRead.class); | |||||
/** 需要返回的数据 **/ | /** 需要返回的数据 **/ | ||||
private List list; | private List list; | ||||
/** 导出的对象 **/ | /** 导出的对象 **/ | ||||
@@ -129,8 +129,9 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||||
*/ | */ | ||||
private void addListData(List<SaxReadCellEntity> datas) throws Exception { | private void addListData(List<SaxReadCellEntity> datas) throws Exception { | ||||
// 判断是集合元素还是不是集合元素,如果是就继续加入这个集合,不是就创建新的对象 | // 判断是集合元素还是不是集合元素,如果是就继续加入这个集合,不是就创建新的对象 | ||||
if ((datas.get(params.getKeyIndex()) == null || StringUtils.isEmpty(String.valueOf(datas | |||||
.get(params.getKeyIndex()).getValue()))) && object != null) { | |||||
if ((datas.get(params.getKeyIndex()) == null | |||||
|| StringUtils.isEmpty(String.valueOf(datas.get(params.getKeyIndex()).getValue()))) | |||||
&& object != null) { | |||||
for (ExcelCollectionParams param : excelCollection) { | for (ExcelCollectionParams param : excelCollection) { | ||||
addListContinue(object, param, datas, titlemap, targetId, params); | addListContinue(object, param, datas, titlemap, targetId, params); | ||||
} | } | ||||
@@ -171,7 +172,8 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||||
private void addListContinue(Object object, ExcelCollectionParams param, | private void addListContinue(Object object, ExcelCollectionParams param, | ||||
List<SaxReadCellEntity> datas, Map<Integer, String> titlemap, | List<SaxReadCellEntity> datas, Map<Integer, String> titlemap, | ||||
String targetId, ImportParams params) throws Exception { | String targetId, ImportParams params) throws Exception { | ||||
Collection collection = (Collection) PoiReflectorUtil.fromCache(pojoClass).getValue(object, param.getName()); | |||||
Collection collection = (Collection) PoiReflectorUtil.fromCache(pojoClass).getValue(object, | |||||
param.getName()); | |||||
Object entity = PoiPublicUtil.createObject(param.getType(), targetId); | Object entity = PoiPublicUtil.createObject(param.getType(), targetId); | ||||
boolean isUsed = false;// 是否需要加上这个对象 | boolean isUsed = false;// 是否需要加上这个对象 | ||||
for (int i = 0; i < datas.size(); i++) { | for (int i = 0; i < datas.size(); i++) { | ||||
@@ -196,8 +198,8 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
private void saveFieldValue(ImportParams params, Object object, SaxReadCellEntity entity, | private void saveFieldValue(ImportParams params, Object object, SaxReadCellEntity entity, | ||||
Map<String, ExcelImportEntity> excelParams, String titleString) | |||||
throws Exception { | |||||
Map<String, ExcelImportEntity> excelParams, | |||||
String titleString) throws Exception { | |||||
Object value = cellValueServer.getValue(params.getDataHanlder(), object, entity, | Object value = cellValueServer.getValue(params.getDataHanlder(), object, entity, | ||||
excelParams, titleString); | excelParams, titleString); | ||||
setValues(excelParams.get(titleString), object, value); | setValues(excelParams.get(titleString), object, value); | ||||
@@ -26,7 +26,7 @@ public class ExcelImportException extends RuntimeException { | |||||
private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
private ExcelImportEnum type; | |||||
private ExcelImportEnum type; | |||||
public ExcelImportException() { | public ExcelImportException() { | ||||
super(); | super(); | ||||
@@ -22,7 +22,9 @@ package org.jeecgframework.poi.exception.excel.enums; | |||||
*/ | */ | ||||
public enum ExcelExportEnum { | public enum ExcelExportEnum { | ||||
PARAMETER_ERROR("Excel 导出 参数错误"), EXPORT_ERROR("Excel导出错误"),TEMPLATE_ERROR("Excel 模板错误"); | |||||
PARAMETER_ERROR ("Excel 导出 参数错误") , | |||||
EXPORT_ERROR ("Excel导出错误") , | |||||
TEMPLATE_ERROR ("Excel 模板错误"); | |||||
private String msg; | private String msg; | ||||
@@ -22,7 +22,9 @@ package org.jeecgframework.poi.exception.excel.enums; | |||||
*/ | */ | ||||
public enum ExcelImportEnum { | public enum ExcelImportEnum { | ||||
IS_NOT_A_VALID_TEMPLATE("不是合法的Excel模板"), GET_VALUE_ERROR("Excel 值获取失败"), VERIFY_ERROR("值校验失败"); | |||||
IS_NOT_A_VALID_TEMPLATE ("不是合法的Excel模板") , | |||||
GET_VALUE_ERROR ("Excel 值获取失败") , | |||||
VERIFY_ERROR ("值校验失败"); | |||||
private String msg; | private String msg; | ||||
@@ -14,18 +14,20 @@ | |||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
package org.jeecgframework.poi.handler.inter; | package org.jeecgframework.poi.handler.inter; | ||||
/** | /** | ||||
* Excel标记类 | * Excel标记类 | ||||
* @author JueYue | * @author JueYue | ||||
* @date 2015年10月31日 下午9:31:47 | * @date 2015年10月31日 下午9:31:47 | ||||
*/ | */ | ||||
public interface IExcelModel { | public interface IExcelModel { | ||||
/** | /** | ||||
* 获取错误数据 | * 获取错误数据 | ||||
* @return | * @return | ||||
*/ | */ | ||||
public String getErrorMsg(); | public String getErrorMsg(); | ||||
/** | /** | ||||
* 设置错误信息 | * 设置错误信息 | ||||
* @param errorMsg | * @param errorMsg | ||||
@@ -15,114 +15,113 @@ import org.apache.poi.ss.util.CellRangeAddress; | |||||
* @see org.jeecgframework.poi.util.PoiCellUtil | * @see org.jeecgframework.poi.util.PoiCellUtil | ||||
* 获取单元格的值 | * 获取单元格的值 | ||||
*/ | */ | ||||
public class PoiCellUtil | |||||
{ | |||||
/** | |||||
* 读取单元格的值 | |||||
* @param sheet | |||||
* @param row | |||||
* @param column | |||||
* @return | |||||
*/ | |||||
public static String getCellValue(Sheet sheet ,int row , int column) | |||||
{ | |||||
String value=null; | |||||
if(isMergedRegion(sheet ,row ,column)){ | |||||
value=getMergedRegionValue(sheet ,row ,column); | |||||
}else{ | |||||
Row rowData=sheet.getRow(row); | |||||
Cell cell=rowData.getCell(column); | |||||
value=getCellValue(cell); | |||||
} | |||||
return value; | |||||
} | |||||
/** | |||||
* 获取合并单元格的值 | |||||
* @param sheet | |||||
* @param row | |||||
* @param column | |||||
* @return | |||||
*/ | |||||
public static String getMergedRegionValue(Sheet sheet ,int row , int column){ | |||||
int sheetMergeCount = sheet.getNumMergedRegions(); | |||||
for(int i = 0 ; i < sheetMergeCount ; i++){ | |||||
CellRangeAddress ca = sheet.getMergedRegion(i); | |||||
int firstColumn = ca.getFirstColumn(); | |||||
int lastColumn = ca.getLastColumn(); | |||||
int firstRow = ca.getFirstRow(); | |||||
int lastRow = ca.getLastRow(); | |||||
if(row >= firstRow && row <= lastRow){ | |||||
if(column >= firstColumn && column <= lastColumn){ | |||||
Row fRow = sheet.getRow(firstRow); | |||||
Cell fCell = fRow.getCell(firstColumn); | |||||
return getCellValue(fCell) ; | |||||
} | |||||
} | |||||
} | |||||
return null ; | |||||
} | |||||
/** | |||||
* 判断指定的单元格是否是合并单元格 | |||||
* @param sheet | |||||
* @param row | |||||
* @param column | |||||
* @return | |||||
*/ | |||||
public static boolean isMergedRegion(Sheet sheet , int row , int column){ | |||||
int sheetMergeCount = sheet.getNumMergedRegions(); | |||||
for(int i = 0 ; i < sheetMergeCount ; i++ ){ | |||||
CellRangeAddress ca = sheet.getMergedRegion(i); | |||||
int firstColumn = ca.getFirstColumn(); | |||||
int lastColumn = ca.getLastColumn(); | |||||
int firstRow = ca.getFirstRow(); | |||||
int lastRow = ca.getLastRow(); | |||||
if(row >= firstRow && row <= lastRow){ | |||||
if(column >= firstColumn && column <= lastColumn){ | |||||
return true ; | |||||
} | |||||
} | |||||
} | |||||
return false ; | |||||
} | |||||
/** | |||||
* 获取单元格的值 | |||||
* @param cell | |||||
* @return | |||||
*/ | |||||
public static String getCellValue(Cell cell){ | |||||
if(cell == null) return ""; | |||||
if(cell.getCellType() == Cell.CELL_TYPE_STRING){ | |||||
return cell.getStringCellValue(); | |||||
}else if(cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){ | |||||
return String.valueOf(cell.getBooleanCellValue()); | |||||
}else if(cell.getCellType() == Cell.CELL_TYPE_FORMULA){ | |||||
return cell.getCellFormula() ; | |||||
}else if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){ | |||||
return String.valueOf(cell.getNumericCellValue()); | |||||
} | |||||
return ""; | |||||
} | |||||
public class PoiCellUtil { | |||||
/** | |||||
* 读取单元格的值 | |||||
* @param sheet | |||||
* @param row | |||||
* @param column | |||||
* @return | |||||
*/ | |||||
public static String getCellValue(Sheet sheet, int row, int column) { | |||||
String value = null; | |||||
if (isMergedRegion(sheet, row, column)) { | |||||
value = getMergedRegionValue(sheet, row, column); | |||||
} else { | |||||
Row rowData = sheet.getRow(row); | |||||
Cell cell = rowData.getCell(column); | |||||
value = getCellValue(cell); | |||||
} | |||||
return value; | |||||
} | |||||
/** | |||||
* 获取合并单元格的值 | |||||
* @param sheet | |||||
* @param row | |||||
* @param column | |||||
* @return | |||||
*/ | |||||
public static String getMergedRegionValue(Sheet sheet, int row, int column) { | |||||
int sheetMergeCount = sheet.getNumMergedRegions(); | |||||
for (int i = 0; i < sheetMergeCount; i++) { | |||||
CellRangeAddress ca = sheet.getMergedRegion(i); | |||||
int firstColumn = ca.getFirstColumn(); | |||||
int lastColumn = ca.getLastColumn(); | |||||
int firstRow = ca.getFirstRow(); | |||||
int lastRow = ca.getLastRow(); | |||||
if (row >= firstRow && row <= lastRow) { | |||||
if (column >= firstColumn && column <= lastColumn) { | |||||
Row fRow = sheet.getRow(firstRow); | |||||
Cell fCell = fRow.getCell(firstColumn); | |||||
return getCellValue(fCell); | |||||
} | |||||
} | |||||
} | |||||
return null; | |||||
} | |||||
/** | |||||
* 判断指定的单元格是否是合并单元格 | |||||
* @param sheet | |||||
* @param row | |||||
* @param column | |||||
* @return | |||||
*/ | |||||
public static boolean isMergedRegion(Sheet sheet, int row, int column) { | |||||
int sheetMergeCount = sheet.getNumMergedRegions(); | |||||
for (int i = 0; i < sheetMergeCount; i++) { | |||||
CellRangeAddress ca = sheet.getMergedRegion(i); | |||||
int firstColumn = ca.getFirstColumn(); | |||||
int lastColumn = ca.getLastColumn(); | |||||
int firstRow = ca.getFirstRow(); | |||||
int lastRow = ca.getLastRow(); | |||||
if (row >= firstRow && row <= lastRow) { | |||||
if (column >= firstColumn && column <= lastColumn) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
/** | |||||
* 获取单元格的值 | |||||
* @param cell | |||||
* @return | |||||
*/ | |||||
public static String getCellValue(Cell cell) { | |||||
if (cell == null) | |||||
return ""; | |||||
if (cell.getCellType() == Cell.CELL_TYPE_STRING) { | |||||
return cell.getStringCellValue(); | |||||
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { | |||||
return String.valueOf(cell.getBooleanCellValue()); | |||||
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) { | |||||
return cell.getCellFormula(); | |||||
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { | |||||
return String.valueOf(cell.getNumericCellValue()); | |||||
} | |||||
return ""; | |||||
} | |||||
} | } |
@@ -25,8 +25,6 @@ import org.jeecgframework.poi.exception.excel.ExcelExportException; | |||||
* @date 2015年4月25日 下午12:13:21 | * @date 2015年4月25日 下午12:13:21 | ||||
*/ | */ | ||||
public final class PoiElUtil { | public final class PoiElUtil { | ||||
public static final String LENGTH = "le:"; | public static final String LENGTH = "le:"; | ||||
public static final String FOREACH = "fe:"; | public static final String FOREACH = "fe:"; | ||||
@@ -41,7 +39,7 @@ public final class PoiElUtil { | |||||
public static final String IF_DELETE = "!if:"; | public static final String IF_DELETE = "!if:"; | ||||
public static final String EMPTY = ""; | public static final String EMPTY = ""; | ||||
public static final String CONST = "'"; | public static final String CONST = "'"; | ||||
public static final String NULL = "&NULL&"; | |||||
public static final String NULL = "&NULL&"; | |||||
public static final String LEFT_BRACKET = "("; | public static final String LEFT_BRACKET = "("; | ||||
public static final String RIGHT_BRACKET = ")"; | public static final String RIGHT_BRACKET = ")"; | ||||
@@ -3,8 +3,6 @@ | |||||
*/ | */ | ||||
package org.jeecgframework.poi.util; | package org.jeecgframework.poi.util; | ||||
import java.util.List; | import java.util.List; | ||||
import org.apache.poi.ss.usermodel.Sheet; | import org.apache.poi.ss.usermodel.Sheet; | ||||
@@ -17,39 +15,36 @@ import org.jeecgframework.poi.excel.graph.entity.ExcelGraphElement; | |||||
* @version 1.0 | * @version 1.0 | ||||
* 构建特殊数据结构 | * 构建特殊数据结构 | ||||
*/ | */ | ||||
public class PoiExcelGraphDataUtil | |||||
{ | |||||
/** | |||||
* 构建获取数据最后行数 并写入到定义对象中 | |||||
* @param dataSourceSheet | |||||
* @param graph | |||||
*/ | |||||
public static void buildGraphData(Sheet dataSourceSheet,ExcelGraph graph){ | |||||
if(graph!=null&&graph.getCategory()!=null&&graph.getValueList()!=null&&graph.getValueList().size()>0){ | |||||
graph.getCategory().setEndRowNum(dataSourceSheet.getLastRowNum()); | |||||
for(ExcelGraphElement e:graph.getValueList()){ | |||||
if(e!=null){ | |||||
e.setEndRowNum(dataSourceSheet.getLastRowNum()); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建多个图形对象 | |||||
* @param dataSourceSheet | |||||
* @param graphList | |||||
*/ | |||||
public static void buildGraphData(Sheet dataSourceSheet,List<ExcelGraph> graphList){ | |||||
if(graphList!=null&&graphList.size()>0){ | |||||
for(ExcelGraph graph:graphList){ | |||||
buildGraphData(dataSourceSheet,graph); | |||||
} | |||||
} | |||||
} | |||||
public class PoiExcelGraphDataUtil { | |||||
/** | |||||
* 构建获取数据最后行数 并写入到定义对象中 | |||||
* @param dataSourceSheet | |||||
* @param graph | |||||
*/ | |||||
public static void buildGraphData(Sheet dataSourceSheet, ExcelGraph graph) { | |||||
if (graph != null && graph.getCategory() != null && graph.getValueList() != null | |||||
&& graph.getValueList().size() > 0) { | |||||
graph.getCategory().setEndRowNum(dataSourceSheet.getLastRowNum()); | |||||
for (ExcelGraphElement e : graph.getValueList()) { | |||||
if (e != null) { | |||||
e.setEndRowNum(dataSourceSheet.getLastRowNum()); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* 构建多个图形对象 | |||||
* @param dataSourceSheet | |||||
* @param graphList | |||||
*/ | |||||
public static void buildGraphData(Sheet dataSourceSheet, List<ExcelGraph> graphList) { | |||||
if (graphList != null && graphList.size() > 0) { | |||||
for (ExcelGraph graph : graphList) { | |||||
buildGraphData(dataSourceSheet, graph); | |||||
} | |||||
} | |||||
} | |||||
} | } |
@@ -179,5 +179,5 @@ public final class PoiFunctionUtil { | |||||
double two = Double.valueOf(second.toString()); | double two = Double.valueOf(second.toString()); | ||||
return one > two; | return one > two; | ||||
} | } | ||||
} | } |
@@ -166,7 +166,8 @@ public final class PoiMergeCellUtil { | |||||
// 存在依赖关系 测试 | // 存在依赖关系 测试 | ||||
if (mergeEntity.getText().equals(text)) { | if (mergeEntity.getText().equals(text)) { | ||||
for (int i = 0; i < delys.length; i++) { | for (int i = 0; i < delys.length; i++) { | ||||
if (mergeEntity.getRelyList().get(i) ==null || !mergeEntity.getRelyList().get(i).equals(getCellNotNullText(cell, delys[i], rowNum))) { | |||||
if (mergeEntity.getRelyList().get(i) == null || !mergeEntity.getRelyList().get(i) | |||||
.equals(getCellNotNullText(cell, delys[i], rowNum))) { | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
@@ -184,13 +185,15 @@ public final class PoiMergeCellUtil { | |||||
* @return | * @return | ||||
*/ | */ | ||||
private static String getCellNotNullText(Cell cell, int index, int rowNum) { | private static String getCellNotNullText(Cell cell, int index, int rowNum) { | ||||
if(cell == null || cell.getRow() == null){ | |||||
if (cell == null || cell.getRow() == null) { | |||||
return null; | return null; | ||||
} | } | ||||
if(cell.getRow().getCell(index) != null && StringUtils.isNotEmpty(cell.getRow().getCell(index).getStringCellValue())){ | |||||
if (cell.getRow().getCell(index) != null | |||||
&& StringUtils.isNotEmpty(cell.getRow().getCell(index).getStringCellValue())) { | |||||
return cell.getRow().getCell(index).getStringCellValue(); | return cell.getRow().getCell(index).getStringCellValue(); | ||||
} | } | ||||
return getCellNotNullText(cell.getRow().getSheet().getRow(--rowNum).getCell(index),index,rowNum); | |||||
return getCellNotNullText(cell.getRow().getSheet().getRow(--rowNum).getCell(index), index, | |||||
rowNum); | |||||
} | } | ||||
} | } |
@@ -100,9 +100,11 @@ public final class PoiPublicUtil { | |||||
} | } | ||||
if (isCollection(field.getType())) { | if (isCollection(field.getType())) { | ||||
ExcelCollection collection = field.getAnnotation(ExcelCollection.class); | ExcelCollection collection = field.getAnnotation(ExcelCollection.class); | ||||
PoiReflectorUtil.fromCache(clazz).setValue(obj , field.getName(), collection.type().newInstance()); | |||||
PoiReflectorUtil.fromCache(clazz).setValue(obj, field.getName(), | |||||
collection.type().newInstance()); | |||||
} else if (!isJavaClass(field)) { | } else if (!isJavaClass(field)) { | ||||
PoiReflectorUtil.fromCache(clazz).setValue(obj , field.getName(), createObject(field.getType(), targetId)); | |||||
PoiReflectorUtil.fromCache(clazz).setValue(obj, field.getName(), | |||||
createObject(field.getType(), targetId)); | |||||
} | } | ||||
} | } | ||||
@@ -163,7 +165,8 @@ public final class PoiPublicUtil { | |||||
* 工作簿对象 | * 工作簿对象 | ||||
* @return Map key:图片单元格索引(1_1)String,value:图片流PictureData | * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData | ||||
*/ | */ | ||||
public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet, HSSFWorkbook workbook) { | |||||
public static Map<String, PictureData> getSheetPictrues03(HSSFSheet sheet, | |||||
HSSFWorkbook workbook) { | |||||
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); | Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); | ||||
List<HSSFPictureData> pictures = workbook.getAllPictures(); | List<HSSFPictureData> pictures = workbook.getAllPictures(); | ||||
if (!pictures.isEmpty()) { | if (!pictures.isEmpty()) { | ||||
@@ -193,7 +196,8 @@ public final class PoiPublicUtil { | |||||
* 工作簿对象 | * 工作簿对象 | ||||
* @return Map key:图片单元格索引(1_1)String,value:图片流PictureData | * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData | ||||
*/ | */ | ||||
public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) { | |||||
public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, | |||||
XSSFWorkbook workbook) { | |||||
Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); | Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>(); | ||||
for (POIXMLDocumentPart dr : sheet.getRelations()) { | for (POIXMLDocumentPart dr : sheet.getRelations()) { | ||||
if (dr instanceof XSSFDrawing) { | if (dr instanceof XSSFDrawing) { | ||||
@@ -266,23 +270,20 @@ public final class PoiPublicUtil { | |||||
boolean boo = true; | boolean boo = true; | ||||
if (field.getAnnotation(ExcelIgnore.class) != null) { | if (field.getAnnotation(ExcelIgnore.class) != null) { | ||||
boo = true; | boo = true; | ||||
} else if (boo | |||||
&& field.getAnnotation(ExcelCollection.class) != null | |||||
} else if (boo && field.getAnnotation(ExcelCollection.class) != null | |||||
&& isUseInThis(field.getAnnotation(ExcelCollection.class).name(), targetId) | && isUseInThis(field.getAnnotation(ExcelCollection.class).name(), targetId) | ||||
&& (exclusionsList == null || !exclusionsList.contains(field.getAnnotation( | |||||
ExcelCollection.class).name()))) { | |||||
&& (exclusionsList == null || !exclusionsList | |||||
.contains(field.getAnnotation(ExcelCollection.class).name()))) { | |||||
boo = false; | boo = false; | ||||
} else if (boo | |||||
&& field.getAnnotation(Excel.class) != null | |||||
} else if (boo && field.getAnnotation(Excel.class) != null | |||||
&& isUseInThis(field.getAnnotation(Excel.class).name(), targetId) | && isUseInThis(field.getAnnotation(Excel.class).name(), targetId) | ||||
&& (exclusionsList == null || !exclusionsList.contains(field.getAnnotation( | |||||
Excel.class).name()))) { | |||||
&& (exclusionsList == null | |||||
|| !exclusionsList.contains(field.getAnnotation(Excel.class).name()))) { | |||||
boo = false; | boo = false; | ||||
} else if (boo | |||||
&& field.getAnnotation(ExcelEntity.class) != null | |||||
} else if (boo && field.getAnnotation(ExcelEntity.class) != null | |||||
&& isUseInThis(field.getAnnotation(ExcelEntity.class).name(), targetId) | && isUseInThis(field.getAnnotation(ExcelEntity.class).name(), targetId) | ||||
&& (exclusionsList == null || !exclusionsList.contains(field.getAnnotation( | |||||
ExcelEntity.class).name()))) { | |||||
&& (exclusionsList == null || !exclusionsList | |||||
.contains(field.getAnnotation(ExcelEntity.class).name()))) { | |||||
boo = false; | boo = false; | ||||
} | } | ||||
return boo; | return boo; | ||||
@@ -331,15 +332,12 @@ public final class PoiPublicUtil { | |||||
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); | ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); | ||||
BufferedImage bufferImg; | BufferedImage bufferImg; | ||||
String path = Thread.currentThread().getContextClassLoader().getResource("").toURI() | String path = Thread.currentThread().getContextClassLoader().getResource("").toURI() | ||||
.getPath() | |||||
+ entity.getUrl(); | |||||
.getPath() + entity.getUrl(); | |||||
path = path.replace("WEB-INF/classes/", ""); | path = path.replace("WEB-INF/classes/", ""); | ||||
path = path.replace("file:/", ""); | path = path.replace("file:/", ""); | ||||
bufferImg = ImageIO.read(new File(path)); | bufferImg = ImageIO.read(new File(path)); | ||||
ImageIO.write( | |||||
bufferImg, | |||||
entity.getUrl().substring(entity.getUrl().indexOf(".") + 1, | |||||
entity.getUrl().length()), byteArrayOut); | |||||
ImageIO.write(bufferImg, entity.getUrl().substring(entity.getUrl().indexOf(".") + 1, | |||||
entity.getUrl().length()), byteArrayOut); | |||||
result[0] = byteArrayOut.toByteArray(); | result[0] = byteArrayOut.toByteArray(); | ||||
type = entity.getUrl().split("/.")[entity.getUrl().split("/.").length - 1]; | type = entity.getUrl().split("/.")[entity.getUrl().split("/.").length - 1]; | ||||
} else { | } else { | ||||
@@ -376,11 +374,12 @@ public final class PoiPublicUtil { | |||||
* @date 2013-11-16 | * @date 2013-11-16 | ||||
* @return | * @return | ||||
*/ | */ | ||||
public static Object getRealValue(String currentText, Map<String, Object> map) throws Exception { | |||||
public static Object getRealValue(String currentText, | |||||
Map<String, Object> map) throws Exception { | |||||
String params = ""; | String params = ""; | ||||
while (currentText.indexOf(START_STR) != -1) { | while (currentText.indexOf(START_STR) != -1) { | ||||
params = currentText | |||||
.substring(currentText.indexOf(START_STR) + 2, currentText.indexOf(END_STR)); | |||||
params = currentText.substring(currentText.indexOf(START_STR) + 2, | |||||
currentText.indexOf(END_STR)); | |||||
Object obj = PoiElUtil.eval(params.trim(), map); | Object obj = PoiElUtil.eval(params.trim(), map); | ||||
//判断图片或者是集合 | //判断图片或者是集合 | ||||
@@ -404,8 +403,8 @@ public final class PoiPublicUtil { | |||||
* @throws Exception | * @throws Exception | ||||
*/ | */ | ||||
@SuppressWarnings("rawtypes") | @SuppressWarnings("rawtypes") | ||||
public static Object getValueDoWhile(Object object, String[] paramsArr, int index) | |||||
throws Exception { | |||||
public static Object getValueDoWhile(Object object, String[] paramsArr, | |||||
int index) throws Exception { | |||||
if (object == null) { | if (object == null) { | ||||
return ""; | return ""; | ||||
} | } | ||||
@@ -415,10 +414,11 @@ public final class PoiPublicUtil { | |||||
if (object instanceof Map) { | if (object instanceof Map) { | ||||
object = ((Map) object).get(paramsArr[index]); | object = ((Map) object).get(paramsArr[index]); | ||||
} else { | } else { | ||||
object = PoiReflectorUtil.fromCache(object.getClass()).getValue(object, paramsArr[index]); | |||||
object = PoiReflectorUtil.fromCache(object.getClass()).getValue(object, | |||||
paramsArr[index]); | |||||
} | } | ||||
return (index == paramsArr.length - 1) ? (object == null ? "" : object) : getValueDoWhile( | |||||
object, paramsArr, ++index); | |||||
return (index == paramsArr.length - 1) ? (object == null ? "" : object) | |||||
: getValueDoWhile(object, paramsArr, ++index); | |||||
} | } | ||||
/** | /** | ||||
@@ -434,14 +434,14 @@ public final class PoiPublicUtil { | |||||
} | } | ||||
return temp; | return temp; | ||||
} | } | ||||
/** | /** | ||||
* 统一 key的获取规则 | * 统一 key的获取规则 | ||||
* @param key | * @param key | ||||
* @param targetId | * @param targetId | ||||
* @return | * @return | ||||
*/ | */ | ||||
public static String getValueByTargetId(String key, String targetId, String defalut){ | |||||
public static String getValueByTargetId(String key, String targetId, String defalut) { | |||||
if (StringUtils.isEmpty(targetId) || key.indexOf("_") < 0) { | if (StringUtils.isEmpty(targetId) || key.indexOf("_") < 0) { | ||||
return key; | return key; | ||||
} | } | ||||
@@ -449,7 +449,7 @@ public final class PoiPublicUtil { | |||||
String[] tempArr; | String[] tempArr; | ||||
for (String str : arr) { | for (String str : arr) { | ||||
tempArr = str.split("_"); | tempArr = str.split("_"); | ||||
if(tempArr == null || tempArr.length < 2){ | |||||
if (tempArr == null || tempArr.length < 2) { | |||||
return defalut; | return defalut; | ||||
} | } | ||||
if (targetId.equals(tempArr[1])) { | if (targetId.equals(tempArr[1])) { | ||||
@@ -458,15 +458,14 @@ public final class PoiPublicUtil { | |||||
} | } | ||||
return defalut; | return defalut; | ||||
} | } | ||||
/** | /** | ||||
* 支持换行操作 | * 支持换行操作 | ||||
* @param currentRun | * @param currentRun | ||||
* @param currentText | * @param currentText | ||||
*/ | */ | ||||
public static void setWordText(XWPFRun currentRun, String currentText) { | public static void setWordText(XWPFRun currentRun, String currentText) { | ||||
if(StringUtils.isNotBlank(currentText)){ | |||||
if (StringUtils.isNotBlank(currentText)) { | |||||
String[] tempArr = currentText.split("\r\n"); | String[] tempArr = currentText.split("\r\n"); | ||||
for (int i = 0, le = tempArr.length - 1; i < le; i++) { | for (int i = 0, le = tempArr.length - 1; i < le; i++) { | ||||
currentRun.setText(tempArr[i], i); | currentRun.setText(tempArr[i], i); | ||||
@@ -476,5 +475,4 @@ public final class PoiPublicUtil { | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -21,11 +21,11 @@ public final class PoiReflectorUtil { | |||||
private static final Map<Class<?>, PoiReflectorUtil> CACHE_REFLECTOR = new ConcurrentHashMap<Class<?>, PoiReflectorUtil>(); | private static final Map<Class<?>, PoiReflectorUtil> CACHE_REFLECTOR = new ConcurrentHashMap<Class<?>, PoiReflectorUtil>(); | ||||
private Map<String, Method> getMethods = new HashMap<String, Method>(); | |||||
private Map<String, Method> setMethods = new HashMap<String, Method>(); | |||||
private List<Field> fieldList = new ArrayList<Field>(); | |||||
private Map<String, Method> getMethods = new HashMap<String, Method>(); | |||||
private Map<String, Method> setMethods = new HashMap<String, Method>(); | |||||
private List<Field> fieldList = new ArrayList<Field>(); | |||||
private Class<?> type; | |||||
private Class<?> type; | |||||
private PoiReflectorUtil(Class<?> clazz) { | private PoiReflectorUtil(Class<?> clazz) { | ||||
addGetMethods(clazz); | addGetMethods(clazz); | ||||
@@ -80,9 +80,10 @@ public final class PoiReflectorUtil { | |||||
if (methodType.equals(getterType)) { | if (methodType.equals(getterType)) { | ||||
throw new RuntimeException( | throw new RuntimeException( | ||||
"Illegal overloaded getter method with ambiguous type for property " | "Illegal overloaded getter method with ambiguous type for property " | ||||
+ propName + " in class " + firstMethod.getDeclaringClass() | |||||
+ ". This breaks the JavaBeans " | |||||
+ "specification and can cause unpredicatble results."); | |||||
+ propName + " in class " | |||||
+ firstMethod.getDeclaringClass() | |||||
+ ". This breaks the JavaBeans " | |||||
+ "specification and can cause unpredicatble results."); | |||||
} else if (methodType.isAssignableFrom(getterType)) { | } else if (methodType.isAssignableFrom(getterType)) { | ||||
// OK getter type is descendant | // OK getter type is descendant | ||||
} else if (getterType.isAssignableFrom(methodType)) { | } else if (getterType.isAssignableFrom(methodType)) { | ||||
@@ -91,9 +92,10 @@ public final class PoiReflectorUtil { | |||||
} else { | } else { | ||||
throw new RuntimeException( | throw new RuntimeException( | ||||
"Illegal overloaded getter method with ambiguous type for property " | "Illegal overloaded getter method with ambiguous type for property " | ||||
+ propName + " in class " + firstMethod.getDeclaringClass() | |||||
+ ". This breaks the JavaBeans " | |||||
+ "specification and can cause unpredicatble results."); | |||||
+ propName + " in class " | |||||
+ firstMethod.getDeclaringClass() | |||||
+ ". This breaks the JavaBeans " | |||||
+ "specification and can cause unpredicatble results."); | |||||
} | } | ||||
} | } | ||||
addGetMethod(propName, getter); | addGetMethod(propName, getter); | ||||
@@ -121,7 +123,7 @@ public final class PoiReflectorUtil { | |||||
} | } | ||||
resolveSetterConflicts(conflictingSetters); | resolveSetterConflicts(conflictingSetters); | ||||
} | } | ||||
private static String methodToProperty(String name) { | private static String methodToProperty(String name) { | ||||
if (name.startsWith("is")) { | if (name.startsWith("is")) { | ||||
name = name.substring(2); | name = name.substring(2); | ||||
@@ -168,9 +170,10 @@ public final class PoiReflectorUtil { | |||||
if (setter == null) { | if (setter == null) { | ||||
throw new RuntimeException( | throw new RuntimeException( | ||||
"Illegal overloaded setter method with ambiguous type for property " | "Illegal overloaded setter method with ambiguous type for property " | ||||
+ propName + " in class " + firstMethod.getDeclaringClass() | |||||
+ ". This breaks the JavaBeans " | |||||
+ "specification and can cause unpredicatble results."); | |||||
+ propName + " in class " | |||||
+ firstMethod.getDeclaringClass() | |||||
+ ". This breaks the JavaBeans " | |||||
+ "specification and can cause unpredicatble results."); | |||||
} | } | ||||
addSetMethod(propName, setter); | addSetMethod(propName, setter); | ||||
} | } | ||||
@@ -292,8 +295,8 @@ public final class PoiReflectorUtil { | |||||
public Method getGetMethod(String propertyName) { | public Method getGetMethod(String propertyName) { | ||||
Method method = getMethods.get(propertyName); | Method method = getMethods.get(propertyName); | ||||
if (method == null) { | if (method == null) { | ||||
throw new RuntimeException("There is no getter for property named '" + propertyName | |||||
+ "' in '" + type + "'"); | |||||
throw new RuntimeException( | |||||
"There is no getter for property named '" + propertyName + "' in '" + type + "'"); | |||||
} | } | ||||
return method; | return method; | ||||
} | } | ||||
@@ -301,8 +304,8 @@ public final class PoiReflectorUtil { | |||||
public Method getSetMethod(String propertyName) { | public Method getSetMethod(String propertyName) { | ||||
Method method = setMethods.get(propertyName); | Method method = setMethods.get(propertyName); | ||||
if (method == null) { | if (method == null) { | ||||
throw new RuntimeException("There is no getter for property named '" + propertyName | |||||
+ "' in '" + type + "'"); | |||||
throw new RuntimeException( | |||||
"There is no getter for property named '" + propertyName + "' in '" + type + "'"); | |||||
} | } | ||||
return method; | return method; | ||||
} | } | ||||
@@ -55,8 +55,8 @@ public class WordExportUtil { | |||||
* 解析数据源 | * 解析数据源 | ||||
* @return | * @return | ||||
*/ | */ | ||||
public static void exportWord07(XWPFDocument document, Map<String, Object> map) | |||||
throws Exception { | |||||
public static void exportWord07(XWPFDocument document, | |||||
Map<String, Object> map) throws Exception { | |||||
new ParseWord07().parseWord(document, map); | new ParseWord07().parseWord(document, map); | ||||
} | } | ||||
@@ -45,8 +45,7 @@ public class MyXWPFDocument extends XWPFDocument { | |||||
+ " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" | + " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" | ||||
+ " <pic:nvPicPr>" | + " <pic:nvPicPr>" | ||||
+ " <pic:cNvPr id=\"%s\" name=\"Generated\"/>" | + " <pic:cNvPr id=\"%s\" name=\"Generated\"/>" | ||||
+ " <pic:cNvPicPr/>" | |||||
+ " </pic:nvPicPr>" | |||||
+ " <pic:cNvPicPr/>" + " </pic:nvPicPr>" | |||||
+ " <pic:blipFill>" | + " <pic:blipFill>" | ||||
+ " <a:blip r:embed=\"%s\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" | + " <a:blip r:embed=\"%s\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" | ||||
+ " <a:stretch>" | + " <a:stretch>" | ||||
@@ -57,10 +56,9 @@ public class MyXWPFDocument extends XWPFDocument { | |||||
+ " <a:ext cx=\"%s\" cy=\"%s\"/>" | + " <a:ext cx=\"%s\" cy=\"%s\"/>" | ||||
+ " </a:xfrm>" | + " </a:xfrm>" | ||||
+ " <a:prstGeom prst=\"rect\">" | + " <a:prstGeom prst=\"rect\">" | ||||
+ " <a:avLst/>" | |||||
+ " </a:prstGeom>" + " </pic:spPr>" | |||||
+ " </pic:pic>" + " </a:graphicData>" | |||||
+ "</a:graphic>"; | |||||
+ " <a:avLst/>" + " </a:prstGeom>" | |||||
+ " </pic:spPr>" + " </pic:pic>" | |||||
+ " </a:graphicData>" + "</a:graphic>"; | |||||
public MyXWPFDocument() { | public MyXWPFDocument() { | ||||
super(); | super(); | ||||
@@ -57,12 +57,15 @@ public class ExcelListEntity extends ExcelBaseParams { | |||||
this.clazz = clazz; | this.clazz = clazz; | ||||
setDataHanlder(dataHanlder); | setDataHanlder(dataHanlder); | ||||
} | } | ||||
public ExcelListEntity(List<?> list, Class<?> clazz, IExcelDataHandler dataHanlder, int headRows) { | |||||
public ExcelListEntity(List<?> list, Class<?> clazz, IExcelDataHandler dataHanlder, | |||||
int headRows) { | |||||
this.list = list; | this.list = list; | ||||
this.clazz = clazz; | this.clazz = clazz; | ||||
this.headRows = headRows; | this.headRows = headRows; | ||||
setDataHanlder(dataHanlder); | setDataHanlder(dataHanlder); | ||||
} | } | ||||
public ExcelListEntity(List<?> list, Class<?> clazz, int headRows) { | public ExcelListEntity(List<?> list, Class<?> clazz, int headRows) { | ||||
this.list = list; | this.list = list; | ||||
this.clazz = clazz; | this.clazz = clazz; | ||||
@@ -100,8 +100,8 @@ public class ExcelEntityParse extends ExportBase { | |||||
* @param styles | * @param styles | ||||
*/ | */ | ||||
public void createListCells(int index, int cellNum, Object obj, | public void createListCells(int index, int cellNum, Object obj, | ||||
List<ExcelExportEntity> excelParams, XWPFTable table) | |||||
throws Exception { | |||||
List<ExcelExportEntity> excelParams, | |||||
XWPFTable table) throws Exception { | |||||
ExcelExportEntity entity; | ExcelExportEntity entity; | ||||
XWPFTableRow row; | XWPFTableRow row; | ||||
if (table.getRow(index) == null) { | if (table.getRow(index) == null) { | ||||
@@ -183,9 +183,11 @@ public class ExcelEntityParse extends ExportBase { | |||||
private void setCellValue(XWPFTableRow row, Object value, int cellNum) { | private void setCellValue(XWPFTableRow row, Object value, int cellNum) { | ||||
if (row.getCell(cellNum++) != null) { | if (row.getCell(cellNum++) != null) { | ||||
row.getCell(cellNum - 1).setText(value == null ? "" : value.toString()); | row.getCell(cellNum - 1).setText(value == null ? "" : value.toString()); | ||||
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(),value == null ? "" : value.toString()); | |||||
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(), | |||||
value == null ? "" : value.toString()); | |||||
} else { | } else { | ||||
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(),value == null ? "" : value.toString()); | |||||
PoiPublicUtil.setWordText(row.createCell().addParagraph().createRun(), | |||||
value == null ? "" : value.toString()); | |||||
} | } | ||||
} | } | ||||
@@ -82,12 +82,13 @@ public final class ExcelMapParse { | |||||
for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) { | for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) { | ||||
String val = eval(params[cellIndex], tempMap).toString(); | String val = eval(params[cellIndex], tempMap).toString(); | ||||
currentRow.getTableCells().get(cellIndex).setText(""); | currentRow.getTableCells().get(cellIndex).setText(""); | ||||
PoiPublicUtil.setWordText(currentRow.getTableCells().get(cellIndex).addParagraph().createRun(),val); | |||||
PoiPublicUtil.setWordText( | |||||
currentRow.getTableCells().get(cellIndex).addParagraph().createRun(), val); | |||||
} | } | ||||
for (; cellIndex < params.length; cellIndex++) { | for (; cellIndex < params.length; cellIndex++) { | ||||
String val = eval(params[cellIndex], tempMap).toString(); | String val = eval(params[cellIndex], tempMap).toString(); | ||||
PoiPublicUtil.setWordText(currentRow.createCell().addParagraph().createRun(),val); | |||||
PoiPublicUtil.setWordText(currentRow.createCell().addParagraph().createRun(), val); | |||||
} | } | ||||
} | } | ||||