xml格式的word wordxml格式解析 例子
- 作者: 小猪666
- 来源: 51数据库
- 2020-04-15
为什么word文档变成了xml格式
通过jodconveter来实现转化(http://www.artofsolving.com/opensource/jodconverter)。
这种方式实现起来比较麻烦,操作有点繁琐,但是能解决上述问题。
通过启动OpenOffice.org的服务端口,实现程序操作opeanoffice实现文件的转换。
贴上代码:mport java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import com.artofsolving.jodconverter.DefaultDocumentFormatRegistry; import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.DocumentFormatRegistry; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; public class test { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub test t = new test(); //File in = new File("d:\\mytest\\test1.pdf"); //File out = new File("d:\\mytest\\test11.html"); FileInputStream input = new FileInputStream("d:\\mytest\\test11.pdf"); FileOutputStream output = new FileOutputStream("d:\\mytest\\test11.doc"); t.convert(input, output); } public void convert(File input, File output) throws Exception { OpenOfficeConnection conn = new SocketOpenOfficeConnection("localhost", 8100); conn.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(conn); converter.convert(input, output); conn.disconnect(); } public void convert(InputStream input, OutputStream output) throws Exception { OpenOfficeConnection conn = new SocketOpenOfficeConnection("localhost", 8100); conn.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(conn); DocumentFormatRegistry registry = new DefaultDocumentFormatRegistry(); converter.convert(input, registry.getFormatByFileExtension("pdf"), output, registry.getFormatByFileExtension("doc")); conn.disconnect(); } }
怎么把XML变成WORD文档?
“x”表示不含宏的 XML 文件,而“m”表示含有宏的 XML 文件。
例如,当您在 Word 中保存文档时,现在默认情况下的文件扩展名是 .docx 而不是 .doc。
将文件另存为模板时,可以看到同一类型的更改。
在早期版本中使用的模板扩展名仍然保留,但现在该扩展名末尾多了一个“x”或“m”。
如果文件包含代码或宏,则必须使用启用宏的新 XML 文件格式保存该文件,即,在文件扩展名末尾添加一个表示宏的“m”。
下表列出了 Word 2010、Excel 2010 和 PowerPoint 2010 中的所有默认文件扩展名。
转载请注明出处51数据库 » xml格式的word