main
黄海 8 months ago
parent 4a1c2a650b
commit 953fe19049

@ -61,20 +61,24 @@ public class C1 {
if (fileName.endsWith(".docx") && !fileName.startsWith("~")) { if (fileName.endsWith(".docx") && !fileName.startsWith("~")) {
System.out.println("正在处理" + cityName + "市州文件..."); System.out.println("正在处理" + cityName + "市州文件...");
//读取文件 //读取文件
System.out.println(file.getAbsolutePath());
//1号模板数据在图表5和28中 //1号模板数据在图表5和28中
int firstChartNumber = 5, secondChartNumber = 28; int firstChartNumber = 5, secondChartNumber = 28;
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber-1, 1); List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber-1, 1); List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
//遍历source1 //遍历source1
if (source1 != null) {
for (List<String> r : source1) { for (List<String> r : source1) {
Row outRow = outSheet.createRow(++rowIndex); Row outRow = outSheet.createRow(++rowIndex);
// 导出数据 // 导出数据
//年份,总量分类,区域分类,总量数值,区域数值,行政区划,上级行政区划 //年份,总量分类,区域分类,总量数值,区域数值,行政区划,上级行政区划
ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "总入园数", "", r.get(4), "", cityName, "云南省")), dataStyle); ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "总入园数", "", r.get(4), "", cityName, "云南省")), dataStyle);
} }
}
//遍历source2 //遍历source2
if (source2 != null) {
for (int i = 0; i < source2.size(); i++) { for (int i = 0; i < source2.size(); i++) {
if (i == 0) continue;//跳过2022年这个年份重复了 if (i == 0) continue;//跳过2022年这个年份重复了
List<String> r = source2.get(i); List<String> r = source2.get(i);
@ -83,7 +87,9 @@ public class C1 {
//年份,总量分类,区域分类,总量数值,区域数值,行政区划,上级行政区划 //年份,总量分类,区域分类,总量数值,区域数值,行政区划,上级行政区划
ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "总入园数", "", r.get(4), "", cityName, "云南省")), dataStyle); ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "总入园数", "", r.get(4), "", cityName, "云南省")), dataStyle);
} }
}
//2022年基数:遍历source2 //2022年基数:遍历source2
if (source2 != null) {
for (int i = 0; i < source2.size(); i++) { for (int i = 0; i < source2.size(); i++) {
List<String> r = source2.get(i); List<String> r = source2.get(i);
Row outRow = outSheet.createRow(++rowIndex); Row outRow = outSheet.createRow(++rowIndex);
@ -92,6 +98,7 @@ public class C1 {
ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "2022年基数(万人)", "", source2.getFirst().get(4), ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "2022年基数(万人)", "", source2.getFirst().get(4),
"", cityName, "云南省")), dataStyle); "", cityName, "云南省")), dataStyle);
} }
}
//城区+镇区+乡村 //城区+镇区+乡村
List<String> areaList = new ArrayList<>(); List<String> areaList = new ArrayList<>();
@ -102,6 +109,7 @@ public class C1 {
for (int k = 0; k < areaList.size(); k++) { for (int k = 0; k < areaList.size(); k++) {
String areaName = areaList.get(k); String areaName = areaList.get(k);
if (source1 != null) {
for (int i = 0; i < source1.size(); i++) { for (int i = 0; i < source1.size(); i++) {
List<String> r = source1.get(i); List<String> r = source1.get(i);
Row outRow = outSheet.createRow(++rowIndex); Row outRow = outSheet.createRow(++rowIndex);
@ -109,6 +117,7 @@ public class C1 {
ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "", areaName, "", ExcelKit.putData(outRow, new ArrayList<>(Arrays.asList(r.getFirst(), "", areaName, "",
r.get(k + 1), cityName, "云南省")), dataStyle); r.get(k + 1), cityName, "云南省")), dataStyle);
} }
}
for (int i = 0; i < source2.size(); i++) { for (int i = 0; i < source2.size(); i++) {
if (i == 0) continue; if (i == 0) continue;
List<String> r = source2.get(i); List<String> r = source2.get(i);

@ -94,8 +94,8 @@ public class C4 {
int firstChartNumber = listNode.get(q).getFirst(), secondChartNumber = listNode.get(q).getSecond(); int firstChartNumber = listNode.get(q).getFirst(), secondChartNumber = listNode.get(q).getSecond();
String stageName=listNode.get(q).getStageName(); String stageName=listNode.get(q).getStageName();
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber-1, 1); List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber-1, 1); List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
String c2 = "总在校生"; String c2 = "总在校生";
//遍历source1 //遍历source1

@ -68,8 +68,8 @@ public class C5 {
//读取文件 //读取文件
//1号模板数据在图表11和34中 //1号模板数据在图表11和34中
int firstChartNumber = 11, secondChartNumber = 34; int firstChartNumber = 11, secondChartNumber = 34;
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber-1, 1); List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber-1, 1); List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
String c2 = "总招生数"; String c2 = "总招生数";
//遍历source1 //遍历source1

@ -68,8 +68,8 @@ public class C6 {
//读取文件 //读取文件
//1号模板数据在图表12和35中 //1号模板数据在图表12和35中
int firstChartNumber = 12, secondChartNumber = 35; int firstChartNumber = 12, secondChartNumber = 35;
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber-1, 1); List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber-1, 1); List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
String c2 = "总在校生数"; String c2 = "总在校生数";
//遍历source1 //遍历source1

@ -18,10 +18,7 @@ import org.dom4j.Element;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
@ -551,21 +548,20 @@ public class ExcelKit {
//在每个已知的图表类型中查找,找到后跳出循环 //在每个已知的图表类型中查找,找到后跳出循环
//声明一个数组,图表的所有类型 //声明一个数组,图表的所有类型
String[] CHART_TYPES = {"lineChart", "barChart"};//折线,柱状 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").element(type).element("ser").element("cat") // 创建一个一维列表,用于存储转换后的列
List<List<String>> transposed = new ArrayList<>();
List<Element> xList = new ArrayList<>();
List<Element> children = root.element("chart").element("plotArea").elements();
for (Element child : children) {
//将CHART_TYPES数组转换为List
List<String> CHART_TYPES_LIST = Arrays.asList(CHART_TYPES);
if (CHART_TYPES_LIST.contains(child.getName())) {
transposed.clear();
// 处理barChart或lineChart节点
//System.out.println("找到图表类型:" + child.getName());
String type = child.getName();
xList = root.element("chart").element("plotArea").element(type).element("ser").element("cat")
.element("numRef").element("numCache").elements("pt"); .element("numRef").element("numCache").elements("pt");
List<Object> listObject = new ArrayList<>(); List<Object> listObject = new ArrayList<>();
@ -597,11 +593,13 @@ public class ExcelKit {
} }
matrix.add(row); matrix.add(row);
} }
//上面生成的数据格式需要行转列,横坐标是年份,纵坐标是数据 //上面生成的数据格式需要行转列,横坐标是年份,纵坐标是数据
int rowCount = matrix.size();// 计算行数和列数 int rowCount = matrix.size();// 计算行数和列数
int colCount = matrix.getFirst().size(); int colCount = matrix.getFirst().size();
// 创建一个一维列表,用于存储转换后的列
List<List<String>> transposed = new ArrayList<>(); //System.out.println("行数:" + rowCount + " " + "列数:" + colCount);
// 遍历每一列 // 遍历每一列
for (int col = 0; col < colCount; col++) { for (int col = 0; col < colCount; col++) {
// 创建一个新的内部列表,用于存储当前列的所有行 // 创建一个新的内部列表,用于存储当前列的所有行
@ -625,6 +623,11 @@ public class ExcelKit {
// 将当前列添加到结果列表中 // 将当前列添加到结果列表中
transposed.add(column); transposed.add(column);
} }
}
}
// printTable(transposed);
// 在每一行的第一列插入年份 // 在每一行的第一列插入年份
for (int i = 0; i < transposed.size(); i++) { for (int i = 0; i < transposed.size(); i++) {
List<String> column = transposed.get(i); List<String> column = transposed.get(i);

File diff suppressed because it is too large Load Diff

@ -14,9 +14,9 @@ public class TestOutSideExcel {
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, ParserConfigurationException, SAXException, XPathExpressionException, DocumentException { public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, ParserConfigurationException, SAXException, XPathExpressionException, DocumentException {
String sourceDoc = "c:/西双版纳州人口变化及其对教育的影响20240420.docx"; String sourceDoc = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\16个州市报告2022\\分析报告20240510\\临沧市人口变化及其对教育的影响20240419.docx";
//需要第几个图表 //需要第几个图表
for (int chartNumber = 1; chartNumber <= 37; chartNumber++) { for (int chartNumber = 5; chartNumber <= 5; chartNumber++) {
System.out.println("正在处理第" + chartNumber + "个图表的信息~"); System.out.println("正在处理第" + chartNumber + "个图表的信息~");
//读取图表 //读取图表
List<List<String>> list = ExcelKit.readChart(sourceDoc, chartNumber); List<List<String>> list = ExcelKit.readChart(sourceDoc, chartNumber);

Loading…
Cancel
Save