DocxToDoc.java word高版本docx转化word2003版本
package word;import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;/*** word高版本docx转化word2003版本* * * @author ZengWenFeng* @date 2019.01.28* @mobile 13805029595* @emai 117791303@qq.com*/
public class DocxToDoc
{public static void main(String[] args) throws IOException{// 读取DOCX文件 FileInputStream inputStream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\1.docx");XWPFDocument document = new XWPFDocument(inputStream);// 创建新的DOC文件 FileOutputStream outputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\1.doc");// 遍历DOCX文档中的段落,并将它们写入DOC文件 for (XWPFParagraph paragraph : document.getParagraphs()){outputStream.write(paragraph.getText().getBytes());outputStream.write("\r\n".getBytes()); // 换行符 }// 关闭输入输出流 inputStream.close();outputStream.close();//System.out.println("ok");}
}
docx:
转化后效果不佳啊,doc:
是不是转换格式问题,高版本的遍历完加进来编程酱紫了!!!