main
黄海 8 months ago
parent e6c432acae
commit 6403d888c7

@ -85,7 +85,7 @@ public class A12 {
//县区名称
//System.out.println(file.getAbsolutePath());
int chartNumber = 36;
List<List<String>> source1 = ExcelKit.readChart(file.getAbsolutePath(), chartNumber, 0);
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), chartNumber, 0);
//需要处理下人与万人的单位兼容
// for (int i = 0; i < source1.size(); i++) {

@ -92,7 +92,7 @@ public class A8 {
//System.out.println("正在进行" + cityName + "-" + areaName + "的数据填充~");
int firstChartNumber = 1;
List<List<String>> source1 =
ExcelKit.readChart(file.getAbsolutePath(), firstChartNumber - 1, 6);//从2017年开始
ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 6);//从2017年开始
}

@ -92,11 +92,11 @@ public class A9 {
//System.out.println("正在进行" + cityName + "-" + areaName + "的数据填充~");
int chartNumber = 2;
List<List<String>> source2 =
ExcelKit.readChart(file.getAbsolutePath(), chartNumber - 1, 6);
ExcelKit.getChartData(file.getAbsolutePath(), chartNumber - 1, 6);
chartNumber = 3;
List<List<String>> source3 =
ExcelKit.readChart(file.getAbsolutePath(), chartNumber - 1, 6);
ExcelKit.getChartData(file.getAbsolutePath(), chartNumber - 1, 6);
}
}

@ -65,8 +65,8 @@ public class C1 {
//1号模板数据在图表5和28中
int firstChartNumber = 5, secondChartNumber = 28;
List<List<String>> source1 = ExcelKit.readChart(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.readChart(file.getAbsolutePath(), secondChartNumber, 1);
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
//遍历source1
if (source1 != null) {

@ -65,9 +65,9 @@ public class C10 {
//数据在图表2,图3
int firstChartNumber = 2, secondChartNumber = 3;
List<List<String>> source1 = ExcelKit.readChart(file.getAbsolutePath(), firstChartNumber - 1, 6);//从2017年开始
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber , 6);//从2017年开始
List<List<String>> source3 = ExcelKit.readChart(file.getAbsolutePath(), secondChartNumber - 1, 2);
List<List<String>> source3 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber , 2);
;//从2023年开始
//遍历source1

@ -66,7 +66,7 @@ public class C11 {
int firstChartNumber = 36, secondChartNumber = 37;
//占地面积37
List<List<String>> source1 = ExcelKit.readChart(file.getAbsolutePath(), firstChartNumber - 1, 1);
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
//年份,学前,小学,初中,高中
// 0 1 2 3 4
//所有相关2022基数的列都使用2022的数据
@ -79,7 +79,7 @@ public class C11 {
int gxjzgJS = (int) (Double.parseDouble(firRow.get(4)) * 10000);//高中教职工2022基数
List<List<String>> source2 = ExcelKit.readChart(file.getAbsolutePath(), secondChartNumber - 1, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
//年份,学前,小学,初中,高中
// 0 1 2 3 4
List<String> secRow = source2.getFirst();

@ -65,8 +65,8 @@ public class C2 {
//1号模板数据在图表6和29中
int firstChartNumber = 6, secondChartNumber = 29;
List<List<String>> source1 = ExcelKit.readChart(file.getAbsolutePath(), firstChartNumber - 1, 1);
List<List<String>> source2 = ExcelKit.readChart(file.getAbsolutePath(), secondChartNumber - 1, 1);
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber, 1);
List<List<String>> source2 = ExcelKit.getChartData(file.getAbsolutePath(), secondChartNumber, 1);
String c2 = "总在园数";
//遍历source1

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

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

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

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

@ -72,7 +72,7 @@ public class C9 {
//chartNumber:第几个图表
//skipRowCount:跳过的行数,2017年开始,第一行是表头第二行开始是2022所以填写了跳过6行
//expectLimit:期望的数据行数,首先用POI进行解析如果获取的行数大于预期行数就是正确的否则就需要二次调用python进行读取
List<List<String>> source = ExcelKit.readChart(file.getAbsolutePath(), chartNumber - 1, 6);
List<List<String>> source = ExcelKit.getChartData(file.getAbsolutePath(), chartNumber - 1, 6);
System.out.println("当前城市数据条目数量=" + source.size());

@ -3,7 +3,6 @@ package com.dsideal.base.Tools.FillData.ExcelKit;
import com.dsideal.base.DataEase.Model.ExcelReader;
import com.jfinal.kit.StrKit;
import org.apache.commons.io.FileUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
@ -352,9 +351,8 @@ public class ExcelKit {
* @param skipRowCount
* @return
* @throws IOException
* @throws InvalidFormatException
*/
public static List<List<String>> getChartDataByXml(String docPath, int chartNumber, int skipRowCount) throws IOException, InvalidFormatException, InterruptedException, DocumentException {
public static List<List<String>> getChartData(String docPath, int chartNumber, int skipRowCount) throws IOException, DocumentException {
List<List<String>> data = readChart(docPath, chartNumber);
//需要跳过前skipRowCount行先要判断一下是不是够跳的不够跳的直接输出错误
if (data == null || data.size() < skipRowCount) {
@ -365,28 +363,6 @@ public class ExcelKit {
return data;
}
public static List<List<String>> readChart(String docPath, int chartNumber, int skipRowCount) throws IOException, InvalidFormatException, DocumentException, InterruptedException {
return getChartDataByXml(docPath, chartNumber, skipRowCount);
// InputStream is = new FileInputStream(docPath);
// ZipSecureFile.setMinInflateRatio(-1.0d);
// XWPFDocument doc = new XWPFDocument(is);
// //排序后的图表
// List<XWPFChart> charts = ExcelKit.getSortListForXWPFChart(doc.getCharts());
//
// if (charts.size() < chartNumber) {
// System.out.println(docPath + ",没有第" + chartNumber + "个图表,请检查!");
// return null;
// }
// XSSFWorkbook workbook = charts.get(chartNumber - 1).getWorkbook();
// List<List<String>> data = ExcelKit.readSheet(workbook, skipRowCount);
// is.close();
// if (data.isEmpty()) {
// System.out.println(docPath + ",第" + chartNumber + "个图表,存在数据外链接情况改用XML方式处理");
// return getChartDataByXml(docPath, chartNumber, skipRowCount);
// }
// return data;
}
/**
* Sheet2

@ -22,7 +22,7 @@ public class C11 {
int firstChartNumber = 36, secondChartNumber = 37;
//占地面积37
List<List<String>> source1 = ExcelKit.readChart(file.getAbsolutePath(), firstChartNumber - 1, 1);
List<List<String>> source1 = ExcelKit.getChartData(file.getAbsolutePath(), firstChartNumber - 1, 1);
ExcelKit.printTable(source1);
}
}

@ -12,7 +12,7 @@ public class TestSingle {
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, DocumentException {
String sourceWord = "c:/西双版纳州人口变化及其对教育的影响20240420.docx";
List<List<String>> list = ExcelKit.readChart(sourceWord, 1);
List<List<String>> list = ExcelKit.getChartData(sourceWord, 1,0);
ExcelKit.printTable(list);
}
}

@ -18,7 +18,7 @@ public class TestOutSideExcel {
for (int chartNumber = 4; chartNumber <= 4; chartNumber++) {
System.out.println("正在处理第" + chartNumber + "个图表的信息~");
//读取图表
List<List<String>> list = ExcelKit.readChart(sourceDoc, chartNumber);
List<List<String>> list = ExcelKit.getChartData(sourceDoc, chartNumber,0);
ExcelKit.printTable(list);
}
}

@ -11,11 +11,11 @@ public class TestXml {
public static void main(String[] args) throws DocumentException, IOException {
String sourceDoc = "c:/西双版纳州人口变化及其对教育的影响20240420.docx";
List<List<String>> res = ExcelKit.readChart(sourceDoc, 1);
List<List<String>> res = ExcelKit.getChartData(sourceDoc, 1,0);
ExcelKit.printTable(res);
// for (int chartNumber = 1; chartNumber <= 37; chartNumber++) {
// String xml = ExcelKit.DocxUnzipDirectory + "word\\charts\\chart" + chartNumber + ".xml";
// List<List<String>> res = ExcelKit.readChart(xml);
// List<List<String>> res = ExcelKit.getChartDataByXml(xml);
// //输出转置后的数据
// System.out.println("正在输出第" + chartNumber + "个图表的数据");
// ExcelKit.printTable(res);

Loading…
Cancel
Save