|
|
|
@ -28,7 +28,41 @@ public class C9 {
|
|
|
|
|
//示例Excel
|
|
|
|
|
static String sampleExcelPath = "D:\\dsWork\\YunNanDsBase\\Doc\\待处理\\市\\【9】总人口变化及预测-双\\总人口变化及预测-双.xlsx";
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InvalidFormatException {
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定文档中指定图表数据
|
|
|
|
|
*
|
|
|
|
|
* @param docPath 文档路径
|
|
|
|
|
* @param chartNumber 图表序号
|
|
|
|
|
* @param skipRowCount 跳过的行数
|
|
|
|
|
* @return 结果数据
|
|
|
|
|
* @throws IOException
|
|
|
|
|
* @throws InvalidFormatException
|
|
|
|
|
*/
|
|
|
|
|
public static List<List<String>> getChartData(String docPath, int chartNumber, int skipRowCount, int expectLimit) 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());
|
|
|
|
|
XSSFWorkbook workbook = charts.get(chartNumber).getWorkbook();
|
|
|
|
|
List<List<String>> data = ExcelKit.readSheet(workbook, skipRowCount);
|
|
|
|
|
workbook.close();
|
|
|
|
|
|
|
|
|
|
//如果达到目标预期的数量,就直接返回poi获取的数据列表
|
|
|
|
|
if (data.size() < expectLimit) {
|
|
|
|
|
System.out.println("数据不足,重新获取数据,现正在使用python_docx进行二次获取数据...");
|
|
|
|
|
//否则调用python+com进行再次获取数据列表,这次获取的可能才是对的
|
|
|
|
|
//写入交互文本文件
|
|
|
|
|
ExcelKit.callPythonPrepare(docPath, chartNumber);
|
|
|
|
|
//对图表进行读取
|
|
|
|
|
ExcelKit.callPythonRead();
|
|
|
|
|
//读取生成的EXCEL,使用POI就可以了
|
|
|
|
|
data = ExcelKit.readSheet(ExcelKit.excelPath, skipRowCount);
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException {
|
|
|
|
|
//初始化数据库连接
|
|
|
|
|
LocalMysqlConnectUtil.Init();
|
|
|
|
|
//实例化
|
|
|
|
@ -65,25 +99,16 @@ public class C9 {
|
|
|
|
|
if (fileName.endsWith(".docx") && !fileName.startsWith("~")) {
|
|
|
|
|
System.out.println("正在处理" + cityName + "市州文件...");
|
|
|
|
|
//读取文件
|
|
|
|
|
String inputUrl = file.getAbsolutePath();
|
|
|
|
|
InputStream is = new FileInputStream(inputUrl);
|
|
|
|
|
ZipSecureFile.setMinInflateRatio(-1.0d);
|
|
|
|
|
XWPFDocument doc = new XWPFDocument(is);
|
|
|
|
|
//排序后的图表
|
|
|
|
|
List<XWPFChart> charts = ExcelKit.getSortListForXWPFChart(doc.getCharts());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//数据在图表1
|
|
|
|
|
int firstChartNumber = 1;
|
|
|
|
|
List<List<String>> source1 = getChartData(file.getAbsolutePath(), firstChartNumber, 6,20);//2017年开始
|
|
|
|
|
|
|
|
|
|
XSSFWorkbook workbook = charts.get(firstChartNumber).getWorkbook();
|
|
|
|
|
// if(cityName.contains("丽江")){
|
|
|
|
|
// System.out.println("丽江");
|
|
|
|
|
// }
|
|
|
|
|
List<List<String>> source1 = ExcelKit.readSheet(workbook, 6);//从2017年开始
|
|
|
|
|
|
|
|
|
|
System.out.println(source1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cityName.contains("丽江")) {
|
|
|
|
|
System.out.println("丽江");
|
|
|
|
|
System.out.println(source1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//遍历source1
|
|
|
|
|
for (List<String> r : source1) {
|
|
|
|
|