|
|
|
@ -26,25 +26,56 @@ public class TestSingle {
|
|
|
|
|
//收集图表
|
|
|
|
|
Set<XWPFChart> chartSet = new HashSet<>();
|
|
|
|
|
for (IBodyElement element : doc.getBodyElements()) {
|
|
|
|
|
//直白的图表
|
|
|
|
|
if (element instanceof XWPFChart chart) {
|
|
|
|
|
System.out.println("===图表===");
|
|
|
|
|
System.out.println(chart.getWorkbook().getSheetAt(0).getSheetName());
|
|
|
|
|
chartSet.add(chart);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//段落
|
|
|
|
|
if (element instanceof XWPFParagraph) {
|
|
|
|
|
for (XWPFRun run : ((XWPFParagraph) element).getRuns()) {
|
|
|
|
|
for (XWPFChart chart : run.getDocument().getCharts()) {
|
|
|
|
|
if (chart != null) {
|
|
|
|
|
System.out.println("===段落===");
|
|
|
|
|
System.out.println(chart.getWorkbook().getSheetAt(0).getSheetName());
|
|
|
|
|
chartSet.add(chart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (element instanceof XWPFTable) {
|
|
|
|
|
XWPFTable table = (XWPFTable) element;
|
|
|
|
|
for (XWPFTableRow row : table.getRows()) {
|
|
|
|
|
for (XWPFTableCell cell : row.getTableCells()) {
|
|
|
|
|
for (IBodyElement cellElement : cell.getBodyElements()) {
|
|
|
|
|
if (cellElement instanceof XWPFChart) {
|
|
|
|
|
XWPFChart chart = (XWPFChart) cellElement;
|
|
|
|
|
System.out.println("===表格===");
|
|
|
|
|
System.out.println(chart.getWorkbook().getSheetAt(0).getSheetName());
|
|
|
|
|
chartSet.add(chart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (element instanceof XWPFHeader || element instanceof XWPFFooter) {
|
|
|
|
|
for (IBodyElement headerElement : ((XWPFHeaderFooter) element).getBodyElements()) {
|
|
|
|
|
if (headerElement instanceof XWPFChart) {
|
|
|
|
|
XWPFChart chart = (XWPFChart) headerElement;
|
|
|
|
|
chartSet.add(chart);
|
|
|
|
|
System.out.println("===页眉 页脚===");
|
|
|
|
|
System.out.println(chart.getWorkbook().getSheetAt(0).getSheetName());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.out.println("图表个数=" + chartSet.size());
|
|
|
|
|
//排序后的图表
|
|
|
|
|
List<XWPFChart> chartList = new ArrayList<>(chartSet);
|
|
|
|
|
|
|
|
|
|
chartList = ExcelKit.getSortListForXWPFChart(chartList);
|
|
|
|
|
|
|
|
|
|
//遍历输出
|
|
|
|
|
for (int i = 0; i < chartList.size(); i++) {
|
|
|
|
|
XWPFChart chart = chartList.get(i);
|
|
|
|
|