소스 검색

重新格式化版本,将原有图形化的服务恢复到默认状态

4.1.3.A
xfworld 9 년 전
부모
커밋
b871a8de6e
7개의 변경된 파일366개의 추가작업 그리고 364개의 파일을 삭제
  1. +216
    -209
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/builder/ExcelChartBuildService.java
  2. +4
    -5
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/constant/ExcelGraphElementType.java
  3. +5
    -6
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/constant/ExcelGraphType.java
  4. +8
    -11
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelGraph.java
  5. +51
    -51
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelGraphDefined.java
  6. +50
    -51
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelGraphElement.java
  7. +32
    -31
      easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelTitleCell.java

+ 216
- 209
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/builder/ExcelChartBuildService.java 파일 보기

@@ -38,218 +38,225 @@ import com.google.common.collect.Lists;
* @version 1.0
*
*/
public class ExcelChartBuildService {
/**
*
* @param workbook
* @param graphList
* @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);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
ExcelGraphElement categoryElement = graph.getCategory();
ExcelGraphElement categoryElement=graph.getCategory();
ChartDataSource categoryChart;
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 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()));
}
}
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()));
}
}

/**
* 构建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);
}
}
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);
}
}
}

/**
*
* @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);
}
}
}
}

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);
}
}
}
}
}

+ 4
- 5
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/constant/ExcelGraphElementType.java 파일 보기

@@ -9,9 +9,8 @@ package org.jeecgframework.poi.excel.graph.constant;
* @version 1.0
* 定义元素类型
*/
public interface ExcelGraphElementType {
public static final Integer STRING_TYPE = 1;
public static final Integer NUMERIC_TYPE = 2;
public interface ExcelGraphElementType
{
public static final Integer StringType=1;
public static final Integer NumericType=2;
}

+ 5
- 6
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/constant/ExcelGraphType.java 파일 보기

@@ -9,10 +9,9 @@ package org.jeecgframework.poi.excel.graph.constant;
* @version 1.0
* 定义图形类型
*/
public interface ExcelGraphType {
public static final Integer LINE_CHART = 1;
public static final Integer SCATTER_CHART = 2;

public interface ExcelGraphType
{
public static final Integer LineChart=1;
public static final Integer ScatterChart=2;
}

+ 8
- 11
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelGraph.java 파일 보기

@@ -9,17 +9,14 @@ import java.util.List;
* @author xfworld
* @since 2016-1-7
* @version 1.0
* @see org.jeecgframework.poi.excel.graph.entity.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();
}

+ 51
- 51
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelGraphDefined.java 파일 보기

@@ -15,56 +15,56 @@ import com.google.common.collect.Lists;
* @version 1.0
*
*/
public class ExcelGraphDefined implements ExcelGraph {
private ExcelGraphElement category;
private List<ExcelGraphElement> valueList = Lists.newArrayList();
private List<ExcelTitleCell> titleCell = Lists.newArrayList();
private Integer graphType = ExcelGraphType.LINE_CHART;
private 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 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 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;
}
}

+ 50
- 51
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelGraphElement.java 파일 보기

@@ -5,61 +5,60 @@ package org.jeecgframework.poi.excel.graph.entity;

import org.jeecgframework.poi.excel.graph.constant.ExcelGraphElementType;


/**
* @author xfworld
* @since 2015-12-30
* @version 1.0
*
*/
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;
}
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;
}
}

+ 32
- 31
easypoi-base/src/main/java/org/jeecgframework/poi/excel/graph/entity/ExcelTitleCell.java 파일 보기

@@ -9,35 +9,36 @@ package org.jeecgframework.poi.excel.graph.entity;
* @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;
}
}

불러오는 중...
취소
저장