From 4e2202121400dada83503c55694a3504bfe017e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Tue, 19 Nov 2024 10:29:20 +0800 Subject: [PATCH] 'commit' --- .../com/dsideal/base/Tools/Test/Sample.xml | 1150 ++++++++++++++--- .../dsideal/base/Tools/Test/TestCityArea.java | 27 + .../base/Tools/Test/TestOutSideExcel.java | 74 +- 3 files changed, 1069 insertions(+), 182 deletions(-) create mode 100644 src/main/java/com/dsideal/base/Tools/Test/TestCityArea.java diff --git a/src/main/java/com/dsideal/base/Tools/Test/Sample.xml b/src/main/java/com/dsideal/base/Tools/Test/Sample.xml index fc2d4a8c..189b8af0 100644 --- a/src/main/java/com/dsideal/base/Tools/Test/Sample.xml +++ b/src/main/java/com/dsideal/base/Tools/Test/Sample.xml @@ -19,17 +19,622 @@ - + + + + + + + + + + + + + + Sheet1!$B$1 + + + + 学前 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sheet1!$A$2:$A$12 + + General + + + 2012 + + + 2013 + + + 2014 + + + 2015 + + + 2016 + + + 2017 + + + 2018 + + + 2019 + + + 2020 + + + 2021 + + + 2022 + + + + + + + Sheet1!$B$2:$B$12 + + General + + + 47.17 + + + 50.25 + + + 68.42 + + + 69.27 + + + 74.82 + + + 80.12 + + + 85.92 + + + 89.12 + + + 90.2 + + + 90.74 + + + 92.03 + + + + + + + + + + + + Sheet1!$C$1 + + + + 小学(净) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sheet1!$A$2:$A$12 + + General + + + 2012 + + + 2013 + + + 2014 + + + 2015 + + + 2016 + + + 2017 + + + 2018 + + + 2019 + + + 2020 + + + 2021 + + + 2022 + + + + + + + Sheet1!$C$2:$C$12 + + General + + + 99.9 + + + 99.66 + + + 99.67 + + + 99.55 + + + 99.75 + + + 99.79 + + + 99.88 + + + 99.92 + + + 99.93 + + + 99.94 + + + 98.02 + + + + + + + + + + + + Sheet1!$D$1 + + + + 巩固率 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sheet1!$A$2:$A$12 + + General + + + 2012 + + + 2013 + + + 2014 + + + 2015 + + + 2016 + + + 2017 + + + 2018 + + + 2019 + + + 2020 + + + 2021 + + + 2022 + + + + + + + Sheet1!$D$2:$D$12 + + General + + + 99.28 + + + 98.77 + + + 84.95 + + + 94.62 + + + 96.07 + + + 97.6 + + + 96.97 + + + + + + + + + + + + Sheet1!$E$1 + + + + 高中 + + + + - + + + @@ -40,65 +645,132 @@ - + + + - + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + @@ -111,16 +783,17 @@ - + - - - + + + + @@ -137,7 +810,7 @@ - + @@ -157,10 +830,10 @@ - '[2012—2022西双版纳州人口数据采集.xlsx]Sheet1 (2)'!$A$3:$A$26 + Sheet1!$A$2:$A$12 General - + 2012 @@ -194,125 +867,228 @@ 2022 - - 2023 - - - 2024 - - - 2025 - - - 2026 - - - 2027 - - - 2028 - - - 2029 - - - 2030 - - - 2031 - - - 2032 - - - 2033 - - - 2034 - - - 2035 - - '[2012—2022西双版纳州人口数据采集.xlsx]Sheet1 (2)'!$C$3:$C$26 + Sheet1!$E$2:$E$12 - 0.0;[Red]0.0 - + General + - 114.9 + 58.33 - 115.2 + 57.61 - 115.7 + 60.85 - 116.4 + 62.86 - 117.2 + 63.39 - 118 + 59.23 - 118.8 + 65.74 - 119.6 + 75.66 - 130.4 + 91.6 - - 130.6 + + 92.46 - - 130.8 + + 92.51 - - 131.8 + + + + + + + + + + + Sheet1!#REF! + + + + - - 131.8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sheet1!$A$2:$A$12 + + General + + + 2012 - - 131.8 + + 2013 - - 131.8 + + 2014 - - 131.7 + + 2015 - - 131.5 + + 2016 - - 131.3 + + 2017 - - 131 + + 2018 - - 130.7 + + 2019 - - 130.4 + + 2020 - - 129.9 + + 2021 - - 129.5 + + 2022 - - 128.9 + + + + + + Sheet1!#REF! + + General + + + 1 @@ -327,27 +1103,13 @@ - - - - - - - - - - - - - - - - + + - + @@ -378,7 +1140,14 @@ - + + + + + + + + @@ -416,14 +1185,15 @@ - - - + + + + - + @@ -431,9 +1201,10 @@ - + + @@ -441,8 +1212,9 @@ - - + + + @@ -453,7 +1225,7 @@ - + @@ -470,12 +1242,26 @@ - 人口数(万人) + 毛入学率( + + + + % + + + - + + + + + + + + @@ -485,7 +1271,7 @@ - + @@ -508,16 +1294,18 @@ - - - + + + + - + + @@ -527,6 +1315,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/com/dsideal/base/Tools/Test/TestCityArea.java b/src/main/java/com/dsideal/base/Tools/Test/TestCityArea.java new file mode 100644 index 00000000..8cf6880d --- /dev/null +++ b/src/main/java/com/dsideal/base/Tools/Test/TestCityArea.java @@ -0,0 +1,27 @@ +package com.dsideal.base.Tools.Test; + +import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil; +import com.dsideal.base.Tools.Util.ReadDocxUtil; +import com.jfinal.plugin.activerecord.Db; +import com.jfinal.plugin.activerecord.Record; + +import java.util.List; + +public class TestCityArea { + public static void main(String[] args) throws Exception { + LocalMysqlConnectUtil.Init(); + //实例化 + ReadDocxUtil ru = new ReadDocxUtil(); + List list = ru.getCityNameList(); + for (String s : list) { + String sql = "select id from t_dm_area where area_name=?"; + String area_id = Db.queryStr(sql, s); + sql = "select * from t_dm_area where parent_id=?"; + List records = Db.find(sql, area_id); + for (Record record : records) { + String area_name = record.getStr("area_name"); + System.out.println(s+" "+area_name); + } + } + } +} diff --git a/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java b/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java index e2b082eb..cb7e99e1 100644 --- a/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java +++ b/src/main/java/com/dsideal/base/Tools/Test/TestOutSideExcel.java @@ -16,7 +16,9 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -66,11 +68,11 @@ public class TestOutSideExcel { * @param chartNumber */ public static List> readChar(String workingPath, int chartNumber) throws DocumentException { - List> res = new ArrayList<>(); + List> matrix = new ArrayList<>(); String xml = workingPath + "\\word\\charts\\chart" + chartNumber + ".xml"; if (!(new File(xml).exists())) { System.out.println("没有找到第" + chartNumber + "个图表"); - return res; + return matrix ; } //3、开始读取 // 创建 SAXReader 对象,读取 XML 文件 @@ -105,35 +107,66 @@ public class TestOutSideExcel { .element("numRef").element("numCache").elements("pt"); - List> allValueList = new ArrayList<>(); + List allValueList = new ArrayList<>(); ///c:chartSpace/c:chart/c:plotArea/c:lineChart/c:ser/c:val/c:numRef/c:numCache for (Element ser : root.element("chart").element("plotArea") .element(type).elements("ser")) { - List yList = ser.element("val") - .element("numRef").element("numCache").elements("pt"); - allValueList.add(yList); + List yList = ser.element("val").element("numRef").element("numCache").elements("pt"); + + //记录都有哪些有效数值和索引号 + Map map = new HashMap<>(); + for (Element e : yList) { + map.put(Integer.parseInt(e.attribute("idx").getValue()), e); + } + List lo = new ArrayList<>(); + for (int i = 0; i < xList.size(); i++) { + if (map.containsKey(i)) { + lo.add(map.get(i)); + } else { + lo.add(null); + } + } + allValueList.add(lo); } - for (int i = 0; i < xList.size(); i++) { + for (int i = 0; i < allValueList.size(); i++) { List row = new ArrayList<>(); - row.add(xList.get(i).element("v").getText()); - - for (int j = 0; j < allValueList.size(); j++) { - List yList = allValueList.get(j); - if (yList == null || i + 1 > yList.size() || yList.get(i) == null) { + List lo = (List) allValueList.get(i); + for (Element e : lo) { + if (e == null) { row.add(null); - continue; - } - Element e = yList.get(i).element("v"); - if (e != null) { - row.add(e.getText()); } else { - row.add(null); + row.add(e.element("v").getText()); } } - res.add(row); + matrix.add(row); } - return res; + //上面生成的数据格式需要行转列,横坐标是年份,纵坐标是数据 + // 计算行数和列数 + int rowCount = matrix.size(); + int colCount = matrix.getFirst().size(); + + // 创建一个一维列表,用于存储转换后的列 + List> transposed = new ArrayList<>(); + + // 遍历每一列 + for (int col = 0; col < colCount; col++) { + // 创建一个新的内部列表,用于存储当前列的所有行 + List column = new ArrayList<>(); + // 遍历每一行,将当前列的值添加到新的内部列表中 + for (int row = 0; row < rowCount; row++) { + column.add(matrix.get(row).get(col)); + } + // 将当前列添加到结果列表中 + transposed.add(column); + } + + // 在每一行的第一列插入序号 + for (int i = 0; i < transposed.size(); i++) { + List column = transposed.get(i); + column.addFirst(xList.get(i).element("v").getText()); // 在每行的开始插入序号 + } + return transposed; } public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, ParserConfigurationException, SAXException, XPathExpressionException, DocumentException { @@ -143,7 +176,6 @@ public class TestOutSideExcel { String workingPath = "C:\\zipFile"; UnCompress(sourceDoc, workingPath); //2、我们需要第几个图表 - for (int chartNumber = 4; chartNumber <= 4; chartNumber++) { System.out.println("正在处理第" + chartNumber + "个图表的信息~"); //读取图表