You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.dsideal.base.Tools.Test;
import cn.hutool.core.io.FileUtil;
import com.dsideal.base.DataEase.Model.DataEaseModel;
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
import com.dsideal.base.Tools.Util.LocalMysqlConnectUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.xwpf.usermodel.XWPFChart;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
public class TestBadExcel {
//开始读取市州word文档
static String parentPath = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\16个州市报告2022\\分析报告20240510";
//示例Excel
static String sampleExcelPath = "D:\\dsWork\\YunNanDsBase\\Doc\\待处理\\市\\【11】教育资源配置发展预测\\教育资源配置发展预测(人).xlsx";
public static void main(String[] args) throws IOException, InvalidFormatException {
//初始化数据库连接
LocalMysqlConnectUtil.Init();
//实例化
//找到parentPath下一级目录中所有文件
List<File> files = FileUtil.loopFiles(parentPath, file -> true);
int rowIndex = 0;
//处理这个目录
if (files != null) {
for (File file : files) {
//判断file是不是目录是目录的需要跳过
if (file.isDirectory()) continue;
//城市名称
DataEaseModel dm=new DataEaseModel();
String cityName = dm.getCityName(file.getName());
String fileName = file.getName();
//判断是否为docx文件
if (fileName.endsWith(".docx") && !fileName.startsWith("~")) {
System.out.println("正在处理" + cityName + "市州文件...");
//读取文件
String inputUrl = file.getAbsolutePath();
InputStream is = new FileInputStream(inputUrl);
ZipSecureFile.setMinInflateRatio(-1.0d);
XWPFDocument doc = new XWPFDocument(is);
//排序后的图表
List<XWPFChart> charts = ExcelKit.getSortListForXWPFChart(doc.getCharts());
//数据在图表36教职工总量
int firstChartNumber = 36;
if(cityName.contains("西双版纳州")){
System.out.println("he");
}
charts.get(firstChartNumber - 1).getWorkbook();
}
}
}
}
}