|
|
|
@ -1,42 +1,44 @@
|
|
|
|
|
package com.dsideal.base.Tools.FillData.Test;
|
|
|
|
|
|
|
|
|
|
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
|
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
|
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
|
import org.apache.poi.openxml4j.util.ZipSecureFile;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
|
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 org.apache.poi.xwpf.usermodel.*;
|
|
|
|
|
import org.docx4j.Docx4J;
|
|
|
|
|
import org.docx4j.openpackaging.exceptions.Docx4JException;
|
|
|
|
|
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
|
|
|
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
|
|
|
|
|
|
|
|
|
|
import javax.xml.bind.SchemaOutputResolver;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class TestSingle {
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException {
|
|
|
|
|
|
|
|
|
|
//处理这个目录
|
|
|
|
|
//判断file是不是目录,是目录的需要跳过
|
|
|
|
|
//城市名称
|
|
|
|
|
File file = new File("c:/1.docx");
|
|
|
|
|
String fileName = file.getAbsolutePath();
|
|
|
|
|
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, Docx4JException {
|
|
|
|
|
|
|
|
|
|
String sourceWord = "c:/1.docx";
|
|
|
|
|
|
|
|
|
|
InputStream is = new FileInputStream(fileName);
|
|
|
|
|
InputStream is = new FileInputStream(sourceWord);
|
|
|
|
|
ZipSecureFile.setMinInflateRatio(-1.0d);
|
|
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
|
|
//排序后的图表
|
|
|
|
|
List<XWPFChart> charts = ExcelKit.getSortListForXWPFChart(doc.getCharts());
|
|
|
|
|
|
|
|
|
|
System.out.println("图表个数=" + charts.size());
|
|
|
|
|
//第34个图表读取不出来
|
|
|
|
|
XSSFWorkbook workbook = charts.get(33).getWorkbook();
|
|
|
|
|
System.out.println("正在读取第34个图表数据...");
|
|
|
|
|
List<List<String>> data = ExcelKit.readSheet(workbook, 2);
|
|
|
|
|
System.out.println("数据条数=" + data.size());
|
|
|
|
|
List<XWPFChart> charts = new ArrayList<>();
|
|
|
|
|
for (IBodyElement element : doc.getBodyElements()) {
|
|
|
|
|
if (element instanceof XWPFChart) {
|
|
|
|
|
charts.add((XWPFChart) element);
|
|
|
|
|
}
|
|
|
|
|
if (element instanceof XWPFParagraph sourcePara) {
|
|
|
|
|
System.out.println(sourcePara.getDocument().getCharts().size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//System.out.println("图表个数=" + charts.size());
|
|
|
|
|
is.close();
|
|
|
|
|
ExcelKit.printTable(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|