main
黄海 8 months ago
parent 97e4ff9f81
commit 3a58bd25de

@ -1,14 +1,23 @@
package com.dsideal.base.Tools.FillData.Test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.dsideal.base.Tools.FillData.ExcelKit.ExcelKit;
import com.dsideal.base.Util.FileUtil;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class TestCallPython {
public static void main(String[] args) throws InterruptedException, IOException {
//设置命令行传入参数
/**
* python+comWORD
*
* @throws IOException
* @throws InterruptedException
*/
public static void readTuBiao() throws IOException, InterruptedException {
// 创建ProcessBuilder对象并设置Python脚本的路径
ProcessBuilder processBuilder = new ProcessBuilder("python", "D:\\dsWork\\YunNanDsBase\\Py\\TuBiao.py");
ProcessBuilder processBuilder = new ProcessBuilder("D:\\anaconda3\\envs\\py310\\python.exe", "D:\\dsWork\\YunNanDsBase\\Py\\TuBiao.py");
// 重定向错误流到标准输出这样可以在Java中捕获所有的输出
processBuilder.redirectErrorStream(true);
// 启动进程
@ -20,7 +29,34 @@ public class TestCallPython {
System.out.println(line);
}
// 等待Python脚本执行完成
int exitCode = process.waitFor();
System.out.println("Python script exited with code " + exitCode);
process.waitFor();
}
public static void main(String[] args) throws InterruptedException, IOException {
//哪个word文档
String docPath = "D:\\dsWork\\YunNanDsBase\\Doc\\全省及州市县区人口与教育报告集20241023\\16个州市报告2022\\分析报告20240510\\红河哈尼族彝族自治州人口变化及其对教育的影响20240419.docx";
//第几个图表
int tuBiaoNum = 1;
String taskTxt = "c:/task.txt";
//Excel文件生成位置
String excelPath="c:/task.xlsx";
//如果文件存在则删除
if (new File(taskTxt).exists()) {
new File(taskTxt).delete();
}
//将docPath写入taskTxt,第一行
//将tuBiaoNum写入taskTxt,第二行
FileWriter writer = new FileWriter(taskTxt, StandardCharsets.UTF_8);
writer.write(docPath);
writer.write("\n");
writer.write(String.valueOf(tuBiaoNum));
writer.write("\n");
writer.flush();
writer.close();
//对图表进行读取
readTuBiao();
//读取生成的EXCEL,使用POI就可以了
List<List<String>> sheetList = ExcelKit.readSheet(excelPath,1);
System.out.println(sheetList);
}
}

Loading…
Cancel
Save