doc文件转化为docx
目前找到doc文件转化为docx比较少,商业版 com.spire.doc 很好用,但是需要收费
查找资料,找到一种利用python脚本,将doc转化docx的实现方式,性能好像很差
Java代码
package com.pdf.pdfdemo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Python {
    public static void main(String[] args) throws Exception
    {
        python2();
    }
    public static void python1() throws  Exception{
        // define the command string
        String commandStr = new String(
                "python E:\\python\\TestMain.py ");
        //Create a Process instance and execute commands
        Process pr = Runtime.getRuntime().exec(commandStr);
        //Get the result produced by executing the above commands
        BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String line = null;
        String result = "";
        while ((line = in.readLine()) != null)
        {
            result += line + "\r\n";
        }
        System.out.println(result);
        in.close();
        int endFlag = pr.waitFor();
        if (endFlag == 0)
        {
            System.out.println("The process is ended normally.");
        }
    }
    public static void python2() throws  Exception{
        try {
            //设置命令行传入参数
            String[] args1 = new String[] { "python", "E:\\python\\test1.py", "E:\\python\\11.doc","E:\\python\\zn2.docx"};
            Process pr = Runtime.getRuntime().exec(args1);
            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            in.close();
            int endFlag = pr.waitFor();
            if (endFlag == 0)
            {
                System.out.println("The process is ended normally.");
            }
            pr.destroy();
            System.out.println("end");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
python脚本
# coding=gbk
import sys
from win32com import client as wc
w = wc.Dispatch('Word.Application')
doc=w.Documents.Open(sys.argv[1])
doc.SaveAs(sys.argv[2],16)#必须有参数16,否则会出错.
需要安装python
来源:CSDN
作者:sliping123
链接:https://blog.csdn.net/sliping123/article/details/104014834