main
黄海 9 months ago
parent 4d2e13140d
commit 0c78cc0ea3

@ -28,36 +28,38 @@ public class TestSingle {
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, Docx4JException { public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException, Docx4JException {
//String sourceWord = "c:/1.docx";
String sourceWord = "c:/1.docx"; String sourceWord = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\16个州市报告2022\\分析报告20240510\\昭通市人口变化及其对教育的影响20240416.docx";
InputStream is = new FileInputStream(sourceWord); InputStream is = new FileInputStream(sourceWord);
ZipSecureFile.setMinInflateRatio(-1.0d); ZipSecureFile.setMinInflateRatio(-1.0d);
XWPFDocument doc = new XWPFDocument(is); XWPFDocument doc = new XWPFDocument(is);
List<XWPFChart> charts = ExcelKit.getSortListForXWPFChart(doc.getCharts()); //收集图表
System.out.println("图表个数=" + charts.size()); List<XWPFChart> chartList = new ArrayList<>();
List<XWPFChart> Mycharts = new ArrayList<>();
for (IBodyElement element : doc.getBodyElements()) { for (IBodyElement element : doc.getBodyElements()) {
if (element instanceof XWPFChart) { if (element instanceof XWPFChart) {
Mycharts.add((XWPFChart) element); chartList.add((XWPFChart) element);
} }
if (element instanceof XWPFParagraph sourcePara) { if (element instanceof XWPFParagraph sourcePara) {
XWPFChart chart = sourcePara.getDocument().getCharts().getFirst(); XWPFChart chart = sourcePara.getDocument().getCharts().getFirst();
XSSFWorkbook workbook = chart.getWorkbook(); if (chart != null && chart.getWorkbook()!=null) chartList.add(chart);
System.out.println(workbook.getSheetAt(0).getSheetName()); }
XSSFSheet sheet = workbook.getSheetAt(0); }
for (Row row : sheet) {
for (Cell cell : row) { //先排序
System.out.print(ExcelKit.readCell(cell)+"\t"); // List<XWPFChart> orderChartList = ExcelKit.getSortListForXWPFChart(chartList);
} System.out.println("图表个数=" + chartList.size());
System.out.println(); //遍历输出
for (XWPFChart chart : chartList) {
XSSFWorkbook workbook = chart.getWorkbook();
XSSFSheet sheet = workbook.getSheetAt(0);
for (Row row : sheet) {
for (Cell cell : row) {
System.out.print(ExcelKit.readCell(cell) + "\t");
} }
// System.out.println(workbook.getSheetAt(0).getPhysicalNumberOfRows()); System.out.println();
// System.out.println(workbook.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
} }
} }
//System.out.println("图表个数=" + charts.size()); //关闭流
is.close(); is.close();
} }
} }

Loading…
Cancel
Save