diff --git a/src/main/java/com/dsideal/base/Tools/Test/Sample.xml b/src/main/java/com/dsideal/base/Tools/Test/Sample.xml new file mode 100644 index 00000000..beddb02d --- /dev/null +++ b/src/main/java/com/dsideal/base/Tools/Test/Sample.xml @@ -0,0 +1,569 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + '[2012—2022西双版纳州人口数据采集.xlsx]Sheet1 (2)'!$A$3:$A$26 + + General + + + 2012 + + + 2013 + + + 2014 + + + 2015 + + + 2016 + + + 2017 + + + 2018 + + + 2019 + + + 2020 + + + 2021 + + + 2022 + + + 2023 + + + 2024 + + + 2025 + + + 2026 + + + 2027 + + + 2028 + + + 2029 + + + 2030 + + + 2031 + + + 2032 + + + 2033 + + + 2034 + + + 2035 + + + + + + + '[2012—2022西双版纳州人口数据采集.xlsx]Sheet1 (2)'!$C$3:$C$26 + + 0.0;[Red]0.0 + + + 114.9 + + + 115.2 + + + 115.7 + + + 116.4 + + + 117.2 + + + 118 + + + 118.8 + + + 119.6 + + + 130.4 + + + 130.6 + + + 130.8 + + + 131.8 + + + 131.8 + + + 131.8 + + + 131.8 + + + 131.7 + + + 131.5 + + + 131.3 + + + 131 + + + 130.7 + + + 130.4 + + + 129.9 + + + 129.5 + + + 128.9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 年份 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 人口数(万人) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java b/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java new file mode 100644 index 00000000..3a438945 --- /dev/null +++ b/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java @@ -0,0 +1,93 @@ +package com.dsideal.base.Tools.Test; + +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.Node; +import org.dom4j.io.SAXReader; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +public class TestOutSideExcel { + /** + * 解压缩 + * + * @throws IOException + */ + public static void compressAndUn(String sourceWordAddress) throws IOException { + File file = new File(sourceWordAddress);//取得word文件 + String dir = "c:\\zipFile\\"; //取得要解压缩文件到的目录 + FileInputStream inputStream = new FileInputStream(file); + ZipInputStream zipInputStream = new ZipInputStream(inputStream); + ZipEntry entry; + byte ch[] = new byte[256]; + while ((entry = zipInputStream.getNextEntry()) != null) { + File zFile = new File(dir + entry.getName()); + if (entry.isDirectory()) { + if (!zFile.exists()) { + zFile.mkdirs(); + } + zipInputStream.closeEntry(); + } else { + File fpath = new File(zFile.getParent()); + if (!fpath.exists()) { + fpath.mkdirs(); + } + FileOutputStream outputStream = new FileOutputStream(zFile); + int i; + while ((i = zipInputStream.read(ch)) != -1) { + outputStream.write(ch, 0, i); + } + zipInputStream.closeEntry(); + outputStream.close(); + } + } + inputStream.close(); + } + + public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, ParserConfigurationException, SAXException, XPathExpressionException, DocumentException { + String sourceDoc = "c:/西双版纳州人口变化及其对教育的影响20240420.docx"; + int chartNumber = 1; + //List> source = ExcelKit.getChartData(sourceDoc, chartNumber - 1, 0); + + compressAndUn(sourceDoc); + //遍历目录 C:\zipFile\word\charts 下面有多少个chart?.xml的文件.下面我们来读取chart1.xml + + String xml="C:\\zipFile\\word\\charts\\chart1.xml"; + // 创建 SAXReader 对象,读取 XML 文件 + SAXReader reader = new SAXReader(); + Document document = reader.read(new File(xml)); + + // 获取根元素 + Element root = document.getRootElement(); + System.out.println("根元素: " + root.getName()); + ///c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:val/c:numRef/c:numCache + List valueList=root.element("chart").element("plotArea") + .element("lineChart").element("ser").element("val") + .element("numRef").element("numCache").elements("pt"); + + for (Element e : valueList) { + System.out.println(e.element("v").getText()); + } + + List yearList=root.element("chart").element("plotArea") + .element("lineChart").element("ser").element("cat") + .element("numRef").element("numCache").elements("pt"); + + for (Element e : yearList) { + System.out.println(e.element("v").getText()); + } + + ///c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:cat/c:numRef/c:numCache/c:pt/c:v + } +}