diff --git a/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测.xlsx b/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测.xlsx index 4bcf3149..91f34c43 100644 Binary files a/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测.xlsx and b/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测.xlsx differ diff --git a/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测【成果】.xlsx b/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测【成果】.xlsx new file mode 100644 index 00000000..ae6cdef4 Binary files /dev/null and b/Doc/待处理/市/【1】学前教育入园总量变化及预测/学前教育入园总量变化及预测【成果】.xlsx differ diff --git a/src/main/java/com/dsideal/base/Tools/FillData/City/C1.java b/src/main/java/com/dsideal/base/Tools/FillData/City/C1.java index 774aebba..dfcc3664 100644 --- a/src/main/java/com/dsideal/base/Tools/FillData/City/C1.java +++ b/src/main/java/com/dsideal/base/Tools/FillData/City/C1.java @@ -68,8 +68,9 @@ public class C1 { ZipSecureFile.setMinInflateRatio(-1.0d); XWPFDocument doc = new XWPFDocument(is); - //图表 - List charts = doc.getCharts(); + //排序后的图表 + List charts = ExcelKit.getSortListForXWPFChart(doc.getCharts()); + //1号模板,数据在图表5和28中 XSSFWorkbook workbook = charts.get(4).getWorkbook(); List> source1 = ExcelKit.readSheet(workbook); @@ -78,7 +79,6 @@ public class C1 { List> source2 = ExcelKit.readSheet(workbook2); //遍历source1 - for (int i = 0; i < source1.size(); i++) { List r = source1.get(i); rowIndex++; @@ -104,7 +104,14 @@ public class C1 { outRow.createCell(0).setCellValue(r.getFirst());//年份 outRow.createCell(1).setCellValue("总入园数");//总量分类 outRow.createCell(2).setCellValue("");//区域分类 - outRow.createCell(3).setCellValue(r.get(4));//总量数值 + + if (4 < r.size()) { + outRow.createCell(3).setCellValue(r.get(4));//总量数值 + } else { + System.out.println(cityName); + outRow.createCell(3).setCellValue("");//总量数值 + } + outRow.createCell(4).setCellValue("");//区域数值 outRow.createCell(5).setCellValue(cityName);//行政区划 outRow.createCell(6).setCellValue("云南省");//上级行政区划 @@ -120,7 +127,13 @@ public class C1 { outRow.createCell(0).setCellValue(r.getFirst());//年份 outRow.createCell(1).setCellValue("2022年基数");//基数 outRow.createCell(2).setCellValue("");//区域分类 - outRow.createCell(3).setCellValue(source2.getFirst().get(4));//总量数值 + + if (4 < source2.getFirst().size()) { + outRow.createCell(3).setCellValue(source2.getFirst().get(4));//总量数值 + } else { + outRow.createCell(3).setCellValue("");//总量数值 + } + outRow.createCell(4).setCellValue("");//区域数值 outRow.createCell(5).setCellValue(cityName);//行政区划 outRow.createCell(6).setCellValue("云南省");//上级行政区划 @@ -161,7 +174,12 @@ public class C1 { outRow.createCell(1).setCellValue("");//基数 outRow.createCell(2).setCellValue(areaName);//区域分类 outRow.createCell(3).setCellValue("");//总量数值 - outRow.createCell(4).setCellValue(r.get(k + 1));//区域数值 + if (k + 1 < r.size()) { + outRow.createCell(4).setCellValue(r.get(k + 1));//区域数值 + } else { + outRow.createCell(4).setCellValue("");//区域数值 + } + outRow.createCell(5).setCellValue(cityName);//行政区划 outRow.createCell(6).setCellValue("云南省");//上级行政区划 //应用一下样式 diff --git a/src/main/java/com/dsideal/base/Tools/FillData/ExcelKit/ExcelKit.java b/src/main/java/com/dsideal/base/Tools/FillData/ExcelKit/ExcelKit.java index 29898d5d..c0142b06 100644 --- a/src/main/java/com/dsideal/base/Tools/FillData/ExcelKit/ExcelKit.java +++ b/src/main/java/com/dsideal/base/Tools/FillData/ExcelKit/ExcelKit.java @@ -7,6 +7,7 @@ import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFFont; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.poi.xwpf.usermodel.XWPFChart; import java.io.File; import java.io.IOException; @@ -116,6 +117,7 @@ public class ExcelKit { //遍历输出sheet的内容 int rowIndex = 0; // 遍历工作表中的所有行 + if(sheet==null) return array; for (Row row : sheet) { rowIndex++; if (rowIndex == 1) continue;//第一行为表头 @@ -199,4 +201,48 @@ public class ExcelKit { outRow.getCell(i).setCellStyle(dataStyle); } } + + + /** + * 对图表List重新排序 + * @param affCharts doc.getCharts() + * @return + */ + public static List getSortListForXWPFChart(List affCharts) { + List charts = new ArrayList<>(); + int itNumber = 0; //计数器 + int oldNumber = 0; //入参计数器 + while (itNumber < affCharts.size()){ + // 从oldCharts.get(0)开始检索,获取排序用图表名 + String name = affCharts.get(oldNumber).getPackagePart().getPartName().toString(); + // 获取此图表排序 + String chartsNum = "";// 图表序号 + boolean flag = false; // 上一个是否为数字 + for (int i = 0; i < name.length(); i++) { + if (chartsNum.equals("") && name.charAt(i)>=48 && name.charAt(i)<=57 ){ + chartsNum += name.charAt(i); + flag = true; + }else if ( flag && name.charAt(i)>=48 && name.charAt(i)<=57){ + chartsNum += name.charAt(i); + flag = true; + }else { + flag = false; + } + } + //对比图表序号数字 + int thisChartNum = Integer.parseInt(chartsNum); + if (thisChartNum == itNumber+1){ //如果相等则加入返回list,且itNumber++ + charts.add(affCharts.get(oldNumber)); + itNumber++; + } + + //入参计数器+1 如果达到最大值则重置为0 + if (oldNumber == affCharts.size()-1){ + oldNumber = 0; + }else{ + oldNumber++; + } + } + return charts; + } }