|
|
|
@ -0,0 +1,45 @@
|
|
|
|
|
package com.dsideal.base.Tools.Test;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
|
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
|
import org.dom4j.DocumentException;
|
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.ParserConfigurationException;
|
|
|
|
|
import javax.xml.xpath.XPathExpressionException;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit.DocxUnzipDirectory;
|
|
|
|
|
|
|
|
|
|
public class CountDocxTuBiao {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, ParserConfigurationException, SAXException, XPathExpressionException, DocumentException {
|
|
|
|
|
//String sourceDoc = "D:\\dsWork\\YunNanDsBase\\Doc\\待处理\\区\\【12】新-教育资源配置发展预测\\(6.11鲁甸县)《县(区)人口变化及其对教育的影响》(4).docx";
|
|
|
|
|
|
|
|
|
|
//找到parentPath下一级目录中所有文件
|
|
|
|
|
String parentPath = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\133个县区报告2022\\县区研究报告";
|
|
|
|
|
List<File> files = FileUtil.loopFiles(parentPath, file -> true);
|
|
|
|
|
//处理这个目录
|
|
|
|
|
if (files != null) {
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
//判断file是不是目录,是目录的需要跳过
|
|
|
|
|
if (file.isDirectory()) continue;
|
|
|
|
|
if (!file.getName().endsWith(".docx") || file.getName().startsWith("~"))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ExcelKit.UnCompress(file.getAbsolutePath());
|
|
|
|
|
for (int chartNumber = 1; ; chartNumber++) {
|
|
|
|
|
String xml = DocxUnzipDirectory + "word\\charts\\chart" + chartNumber + ".xml";
|
|
|
|
|
if (!new File(xml).exists()) {
|
|
|
|
|
System.out.println(file.getName() + " 共" + chartNumber + "个图表");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|