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.

44 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.dsideal.base.Tools.Test;
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
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 java.util.List;
public class TestC2 {
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException {
//处理这个目录
//判断file是不是目录是目录的需要跳过
//城市名称
File file = new File("D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\16个州市报告2022\\分析报告20240510\\昭通市人口变化及其对教育的影响20240416.docx");
String fileName = file.getAbsolutePath();
InputStream is = new FileInputStream(fileName);
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());
is.close();
ExcelKit.printTable(data);
}
}