PoiExcelGraphDataUtil.java
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.bckefu.excel.util;
import com.bckefu.excel.graph.entity.ExcelGraph;
import com.bckefu.excel.graph.entity.ExcelGraphElement;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Sheet;
import java.util.List;
/**
* @author caoliang1918@aliyun.com
* @Date 2017/11/5:23:23
*/
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);
}
}
}
/**
* 获取画布,没有就创建一个
*
* @param sheet
* @return
*/
public static Drawing getDrawingPatriarch(Sheet sheet) {
if (sheet.getDrawingPatriarch() == null) {
sheet.createDrawingPatriarch();
}
return sheet.getDrawingPatriarch();
}
}