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.
57 lines
2.2 KiB
57 lines
2.2 KiB
9 months ago
|
package com.dsideal.base.Test;
|
||
|
|
||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
||
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||
|
import org.apache.poi.xwpf.usermodel.XWPFChart;
|
||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||
|
|
||
|
import java.io.*;
|
||
|
import java.util.List;
|
||
|
|
||
|
public class ReadDoc {
|
||
|
//https://blog.csdn.net/a346736962/article/details/123037797
|
||
|
public static void main(String[] args) throws IOException, InvalidFormatException {
|
||
|
final String inputUrl = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\133个县区报告2022\\县区研究报告\\保山市各县区报告5\\昌宁县人口变化及其对教育的影响.docx";
|
||
|
InputStream is = new FileInputStream(inputUrl);
|
||
|
XWPFDocument doc = new XWPFDocument(is);
|
||
|
//图表
|
||
|
List<XWPFChart> charts = doc.getCharts();
|
||
|
|
||
|
System.out.println("图表数量="+charts.size());
|
||
|
|
||
|
for (XWPFChart chart : charts) {
|
||
|
XSSFWorkbook workbook = chart.getWorkbook();
|
||
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
||
|
//遍历一下sheet
|
||
|
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) {
|
||
|
//遍历行
|
||
|
XSSFRow row = sheet.getRow(i);
|
||
|
if(row==null) continue;
|
||
|
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
|
||
|
//遍历列
|
||
|
XSSFCell cell = row.getCell(j);
|
||
|
if (cell != null)
|
||
|
System.out.print(cell + " ");
|
||
|
else{
|
||
|
System.out.print("null ");
|
||
|
}
|
||
|
}
|
||
|
System.out.println();
|
||
|
}
|
||
|
}
|
||
|
//段落
|
||
|
List<XWPFParagraph> paragraphs = doc.getParagraphs();
|
||
|
for (XWPFParagraph paragraph : paragraphs) {
|
||
|
String text = paragraph.getText();
|
||
|
if(text.startsWith("图")){
|
||
|
System.out.println(text);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|