main
黄海 8 months ago
parent 5d07cf55cb
commit fdbbfd0326

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<c:chartSpace xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" <c:chartSpace
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<c:date1904 val="false"/> <c:date1904 val="false"/>
<c:lang val="zh-CN"/> <c:lang val="zh-CN"/>
<c:roundedCorners val="false"/> <c:roundedCorners val="false"/>
<mc:AlternateContent xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"> <mc:AlternateContent
<mc:Choice Requires="c14" xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart"> xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
<mc:Choice Requires="c14"
xmlns:c14="http://schemas.microsoft.com/office/drawing/2007/8/2/chart">
<c14:style val="102"/> <c14:style val="102"/>
</mc:Choice> </mc:Choice>
<mc:Fallback> <mc:Fallback>
@ -104,14 +107,11 @@
<a:effectLst/> <a:effectLst/>
</c:spPr> </c:spPr>
<c:txPr> <c:txPr>
<a:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" <a:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" lIns="38100" tIns="19050" rIns="38100" bIns="19050" anchor="ctr" anchorCtr="true"/>
lIns="38100" tIns="19050" rIns="38100" bIns="19050" anchor="ctr"
anchorCtr="true"/>
<a:lstStyle/> <a:lstStyle/>
<a:p> <a:p>
<a:pPr> <a:pPr>
<a:defRPr lang="zh-CN" sz="1000" b="0" i="0" u="none" strike="noStrike" kern="1200" <a:defRPr lang="zh-CN" sz="1000" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">
baseline="0">
<a:solidFill> <a:solidFill>
<a:schemeClr val="tx1"> <a:schemeClr val="tx1">
<a:lumMod val="75000"/> <a:lumMod val="75000"/>
@ -135,7 +135,7 @@
<c:showLeaderLines val="false"/> <c:showLeaderLines val="false"/>
<c:extLst> <c:extLst>
<c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}" <c:ext uri="{CE6537A1-D6FC-4f65-9D91-7224C49458BB}"
xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart"> xmlns:c15="http://schemas.microsoft.com/office/drawing/2012/chart">
<c15:layout/> <c15:layout/>
<c15:showLeaderLines val="true"/> <c15:showLeaderLines val="true"/>
<c15:leaderLines> <c15:leaderLines>
@ -356,13 +356,11 @@
<c:title> <c:title>
<c:tx> <c:tx>
<c:rich> <c:rich>
<a:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" <a:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" anchor="ctr" anchorCtr="true"/>
anchor="ctr" anchorCtr="true"/>
<a:lstStyle/> <a:lstStyle/>
<a:p> <a:p>
<a:pPr defTabSz="914400"> <a:pPr defTabSz="914400">
<a:defRPr lang="zh-CN" sz="1000" b="0" i="0" u="none" strike="noStrike" kern="1200" <a:defRPr lang="zh-CN" sz="1000" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">
baseline="0">
<a:solidFill> <a:solidFill>
<a:schemeClr val="tx1"> <a:schemeClr val="tx1">
<a:lumMod val="65000"/> <a:lumMod val="65000"/>
@ -407,13 +405,11 @@
<a:effectLst/> <a:effectLst/>
</c:spPr> </c:spPr>
<c:txPr> <c:txPr>
<a:bodyPr rot="-60000000" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" <a:bodyPr rot="-60000000" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" anchor="ctr" anchorCtr="true"/>
anchor="ctr" anchorCtr="true"/>
<a:lstStyle/> <a:lstStyle/>
<a:p> <a:p>
<a:pPr> <a:pPr>
<a:defRPr lang="zh-CN" sz="900" b="0" i="0" u="none" strike="noStrike" kern="1200" <a:defRPr lang="zh-CN" sz="900" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">
baseline="0">
<a:solidFill> <a:solidFill>
<a:schemeClr val="tx1"> <a:schemeClr val="tx1">
<a:lumMod val="65000"/> <a:lumMod val="65000"/>
@ -457,13 +453,11 @@
<c:title> <c:title>
<c:tx> <c:tx>
<c:rich> <c:rich>
<a:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="ellipsis" vert="mongolianVert" <a:bodyPr rot="0" spcFirstLastPara="0" vertOverflow="ellipsis" vert="mongolianVert" wrap="square" anchor="ctr" anchorCtr="true"/>
wrap="square" anchor="ctr" anchorCtr="true"/>
<a:lstStyle/> <a:lstStyle/>
<a:p> <a:p>
<a:pPr defTabSz="914400"> <a:pPr defTabSz="914400">
<a:defRPr lang="zh-CN" sz="1000" b="0" i="0" u="none" strike="noStrike" kern="1200" <a:defRPr lang="zh-CN" sz="1000" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">
baseline="0">
<a:solidFill> <a:solidFill>
<a:schemeClr val="tx1"> <a:schemeClr val="tx1">
<a:lumMod val="65000"/> <a:lumMod val="65000"/>
@ -503,13 +497,11 @@
<a:effectLst/> <a:effectLst/>
</c:spPr> </c:spPr>
<c:txPr> <c:txPr>
<a:bodyPr rot="-60000000" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" <a:bodyPr rot="-60000000" spcFirstLastPara="0" vertOverflow="ellipsis" vert="horz" wrap="square" anchor="ctr" anchorCtr="true"/>
anchor="ctr" anchorCtr="true"/>
<a:lstStyle/> <a:lstStyle/>
<a:p> <a:p>
<a:pPr> <a:pPr>
<a:defRPr lang="zh-CN" sz="900" b="0" i="0" u="none" strike="noStrike" kern="1200" <a:defRPr lang="zh-CN" sz="900" b="0" i="0" u="none" strike="noStrike" kern="1200" baseline="0">
baseline="0">
<a:solidFill> <a:solidFill>
<a:schemeClr val="tx1"> <a:schemeClr val="tx1">
<a:lumMod val="65000"/> <a:lumMod val="65000"/>

@ -1,6 +1,7 @@
package com.dsideal.base.Tools.Test; package com.dsideal.base.Tools.Test;
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit; import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
import com.jfinal.kit.StrKit;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
@ -57,10 +58,6 @@ public class TestOutSideExcel {
inputStream.close(); inputStream.close();
} }
//折线图
public static String LINE = "lineChart";
//柱状图
public static String BAR = "barChart";
/** /**
* Chart * Chart
@ -68,7 +65,7 @@ public class TestOutSideExcel {
* @param workingPath * @param workingPath
* @param chartNumber * @param chartNumber
*/ */
public static List<List<String>> readChar(String workingPath, int chartNumber, String type) throws DocumentException { public static List<List<String>> readChar(String workingPath, int chartNumber) throws DocumentException {
List<List<String>> res = new ArrayList<>(); List<List<String>> res = new ArrayList<>();
String xml = workingPath + "\\word\\charts\\chart" + chartNumber + ".xml"; String xml = workingPath + "\\word\\charts\\chart" + chartNumber + ".xml";
if (!(new File(xml).exists())) { if (!(new File(xml).exists())) {
@ -84,6 +81,25 @@ public class TestOutSideExcel {
//折线图 //折线图
//将xml用IDEA打开搜索关键的数据值然后右键查看XPATH完整路径可以获取到下面的路径 //将xml用IDEA打开搜索关键的数据值然后右键查看XPATH完整路径可以获取到下面的路径
///c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:cat/c:numRef/c:numCache/c:pt/c:v ///c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:cat/c:numRef/c:numCache/c:pt/c:v
//在每个已知的图表类型中查找,找到后跳出循环
//声明一个数组,图表的所有类型
String[] CHART_TYPES = {"lineChart", "barChart"};//折线,柱状
String type = "";
for (String chartType : CHART_TYPES) {
if (root.element("chart").element("plotArea")
.element(chartType) != null) {
type = chartType;
break;
}
}
if (StrKit.isBlank(type)) {
System.out.println("没有找到图表类型,请扩充图表类型");
System.out.println(root.element("chart").element("plotArea"));
System.exit(-1);
}
List<Element> xList = root.element("chart").element("plotArea") List<Element> xList = root.element("chart").element("plotArea")
.element(type).element("ser").element("cat") .element(type).element("ser").element("cat")
.element("numRef").element("numCache").elements("pt"); .element("numRef").element("numCache").elements("pt");
@ -104,7 +120,16 @@ public class TestOutSideExcel {
for (int j = 0; j < allValueList.size(); j++) { for (int j = 0; j < allValueList.size(); j++) {
List<Element> yList = allValueList.get(j); List<Element> yList = allValueList.get(j);
row.add(yList.get(i).element("v").getText()); if (yList == null || i + 1 > yList.size() || yList.get(i) == null) {
row.add(null);
continue;
}
Element e = yList.get(i).element("v");
if (e != null) {
row.add(e.getText());
} else {
row.add(null);
}
} }
res.add(row); res.add(row);
} }
@ -118,16 +143,13 @@ public class TestOutSideExcel {
String workingPath = "C:\\zipFile"; String workingPath = "C:\\zipFile";
UnCompress(sourceDoc, workingPath); UnCompress(sourceDoc, workingPath);
//2、我们需要第几个图表 //2、我们需要第几个图表
int chartNumber = 1;
//读取第一个图表
List<List<String>> list1 = readChar(workingPath, chartNumber, LINE);
ExcelKit.printTable(list1);
System.out.println("========================================================="); for (int chartNumber = 4; chartNumber <= 4; chartNumber++) {
System.out.println("正在处理第" + chartNumber + "个图表的信息~");
//读取第二个图表 //读取图表
chartNumber = 2; List<List<String>> list = readChar(workingPath, chartNumber);
List<List<String>> list2 = readChar(workingPath, chartNumber, BAR); ExcelKit.printTable(list);
ExcelKit.printTable(list2); System.out.println("=========================================================");
}
} }
} }

Loading…
Cancel
Save