使用“.dotx"转换文件扩展(模板)到“docx"(字文件) [英] Converting a file with ".dotx" extension (template) to "docx" (Word File)
本文介绍了使用“.dotx"转换文件扩展(模板)到“docx"(字文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 POI API 或 Docx4j 将.dotx"Word 模板转换为普通的.docx"?
How to convert a ".dotx" Word template to a plain ".docx" using a POI APIs or Docx4j?
推荐答案
需要从 application/vnd.openxmlformats-officedocument 更改
到 /word/document.xml
的内容类型.wordprocessingml.template.main+xmlapplication/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml
.
The need is changing the content type of /word/document.xml
from application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml
to application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml
.
使用apache poi 4.0.1
的例子:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.xwpf.usermodel.*;
public class WordReadDOTXSaveDOCX {
public static void main(String[] args) throws Exception {
XWPFDocument document = new XWPFDocument(new FileInputStream("StudentReport.dotx"));
document.getPackage().replaceContentType(
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
FileOutputStream out = new FileOutputStream("TheDocumentFromDOTXTemplate.docx");
document.write(out);
out.close();
document.close();
}
}
这篇关于使用“.dotx"转换文件扩展(模板)到“docx"(字文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文