|
|
|
@ -360,24 +360,15 @@ public class ExcelKit {
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws InvalidFormatException
|
|
|
|
|
*/
|
|
|
|
|
public static List<List<String>> getChartData(String docPath, int chartNumber, int skipRowCount) throws IOException, InvalidFormatException, InterruptedException {
|
|
|
|
|
InputStream is = new FileInputStream(docPath);
|
|
|
|
|
ZipSecureFile.setMinInflateRatio(-1.0d);
|
|
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
|
|
//排序后的图表
|
|
|
|
|
List<XWPFChart> charts = ExcelKit.getSortListForXWPFChart(doc.getCharts());
|
|
|
|
|
|
|
|
|
|
if (charts.size() < chartNumber + 1) {
|
|
|
|
|
System.out.println(docPath + ",没有第" + (chartNumber + 1) + "个图表,请检查!");
|
|
|
|
|
public static List<List<String>> getChartData(String docPath, int chartNumber, int skipRowCount) throws IOException, InvalidFormatException, InterruptedException, DocumentException {
|
|
|
|
|
List<List<String>> data = readChart(docPath, chartNumber);
|
|
|
|
|
//需要跳过前skipRowCount行,先要判断一下是不是够跳的,不够跳的直接输出错误
|
|
|
|
|
if (data.size() < skipRowCount) {
|
|
|
|
|
System.out.println("skipRowCount is too big, please check your data.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
XSSFWorkbook workbook = charts.get(chartNumber).getWorkbook();
|
|
|
|
|
List<List<String>> data = ExcelKit.readSheet(workbook, skipRowCount);
|
|
|
|
|
is.close();
|
|
|
|
|
if (data.isEmpty()) {
|
|
|
|
|
System.out.println(docPath + ",第" + (chartNumber + 1) + "个图表,存在数据外链接情况,请人为处理!");
|
|
|
|
|
// System.exit(-1);
|
|
|
|
|
}
|
|
|
|
|
//截取部分数据返回
|
|
|
|
|
data = data.subList(skipRowCount, data.size());
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -492,51 +483,6 @@ public class ExcelKit {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 输出Sheet
|
|
|
|
|
*
|
|
|
|
|
* @param sheet
|
|
|
|
|
*/
|
|
|
|
|
public static void printSheet(XSSFSheet sheet) {
|
|
|
|
|
for (Row row : sheet) {
|
|
|
|
|
for (Cell cell : row) {
|
|
|
|
|
System.out.print(ExcelKit.readCell(cell) + "\t");
|
|
|
|
|
}
|
|
|
|
|
System.out.println();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void ReadChart(String sourceWord) throws IOException, InvalidFormatException {
|
|
|
|
|
InputStream is = new FileInputStream(sourceWord);
|
|
|
|
|
ZipSecureFile.setMinInflateRatio(-1.0d);
|
|
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
|
|
//直接输出图表数量
|
|
|
|
|
System.out.println("doc.getCharts=" + doc.getCharts().size());
|
|
|
|
|
List<XWPFChart> chartList = doc.getCharts();
|
|
|
|
|
//排序后的图表
|
|
|
|
|
chartList = ExcelKit.getSortListForXWPFChart(chartList);
|
|
|
|
|
|
|
|
|
|
//遍历输出
|
|
|
|
|
for (int i = 0; i < chartList.size(); i++) {
|
|
|
|
|
XWPFChart chart = chartList.get(i);
|
|
|
|
|
XSSFWorkbook workbook = chart.getWorkbook();
|
|
|
|
|
System.out.println(workbook.getNumberOfSheets());
|
|
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
|
|
System.out.println("序号=" + (i + 1) + ",sheet名称=" + sheet.getSheetName());
|
|
|
|
|
if (sheet.getPhysicalNumberOfRows() == 0) {
|
|
|
|
|
System.out.println("===第" + (i + 1) + "个图表需要人工编辑一下Sheet名称,否则无法读取!===");
|
|
|
|
|
System.exit(0);
|
|
|
|
|
}
|
|
|
|
|
for (Row row : sheet) {
|
|
|
|
|
for (Cell cell : row) {
|
|
|
|
|
System.out.print(ExcelKit.readCell(cell) + "\t");
|
|
|
|
|
}
|
|
|
|
|
System.out.println();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//关闭流
|
|
|
|
|
is.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解压缩
|
|
|
|
|