convert doc to docx
来源:互联网 发布:上海c语言培训 编辑:程序博客网 时间:2024/04/27 17:53
由于项目需要,收集了各种word2003转换word2007方法,在此提供给大家。
1)You may try Aspose.Words for Java. It allows you to load a DOC file and save it as DOCX format. The code is very simple as shown below:
// Open a document. Document doc = new Document("input.doc"); // Save document. doc.save("output.docx");
Please see if this helps in your scenario.
Disclosure: I work as developer evangelist at Aspose.
2)To convert DOC file to HTML look at this (Convert Word doc to HTML programmatically in Java)
Use this: http://poi.apache.org/
Or use this :
XWPFDocument docx = new XWPFDocument(OPCPackage.openOrCreate(new File("hello.docx"))); XWPFWordExtractor wx = new XWPFWordExtractor(docx); String text = wx.getText(); System.out.println("text = "+text);
3)JODConvertor calls OpenOffice/LibreOffice via a network protocol. It can therefore 'do anything you can do in OpenOffice'. This includes converting formats. But it only does as good a job as whatever version of OpenOffice you are running. I have some art in one of my docs, and it doesn't convert them as I hoped.
JODConvertor is no longer supported, according to the google code web site for v3.
To get JOD to do the job you need to do something like
private static void transformBinaryWordDocToDocX(File in, File out){ OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx"); docx.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2007 XML")); converter.convert(in, out, docx);}private static void transformBinaryWordDocToW2003Xml(File in, File out){ OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager);; DocumentFormat w2003xml = new DocumentFormat("Microsoft Word 2003 XML", "xml", "text/xml"); w2003xml.setInputFamily(DocumentFamily.TEXT); w2003xml.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2003 XML")); converter.convert(in, out, w2003xml);}private static OfficeManager officeManager;@BeforeClasspublic static void setupStatic() throws IOException { /*officeManager = new DefaultOfficeManagerConfiguration() .setOfficeHome("C:/Program Files/LibreOffice 3.6") .buildOfficeManager(); */ officeManager = new ExternalOfficeManagerConfiguration().setConnectOnStart(true).setPortNumber(8100).buildOfficeManager(); officeManager.start();}@AfterClasspublic static void shutdownStatic() throws IOException { officeManager.stop();}
For this to work you need to be running LibreOffice as a networked server ( I could not get the 'run on demand' part of JODConvertor to work under windows with LO 3.6 very well )
4)I needed the same conversion ,after researching a lot found Jodconvertor can be useful in it , you can download the jar fromhttps://code.google.com/p/jodconverter/downloads/list
Add jodconverter-core-3.0-beta-4-sources.jar file to your project lib
//1) Create OfficeManger Object OfficeManager officeManager = new DefaultOfficeManagerConfiguration() .setOfficeHome(new File("/opt/libreoffice4.4")) .buildOfficeManager(); officeManager.start(); // 2) Create JODConverter converter OfficeDocumentConverter converter = new OfficeDocumentConverter( officeManager);// 3)Create DocumentFormat for docxDocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx"); docx.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "MS Word 2007 XML"));//4)Call convert funtion in converter objectconverter.convert(new File("doc/AdvancedTable.doc"), new File( "docx/AdvancedTable.docx"), docx);
- convert doc to docx
- How to convert docx/odt to pdf/html with Java?
- Doc、Docx转成HTML
- office2007 .docx 转成 2003 .doc
- openoffice3.* doc/docx转pdf
- 如何把docx转成doc
- 批量将doc转为docx
- java导出doc和docx
- DOC与DOCX的区别
- doc convert out
- 导入(doc,docx,pdf格式)简历,doc/docx,转pdf格式,并且检索doc,docx,pdf,字段
- 导入(doc,docx,pdf格式)简历,doc/docx,转pdf格式,并且检索doc,docx,pdf,字段
- Converting .docx into (.doc, .pdf, .html)
- android解析doc,docx,xls,xlsx文件
- POI实现DOC/DOCX转HTML
- docx转doc工具(软件)
- POI读取.doc 和.docx的区别
- Liunx 下如何打开doc和docx
- Socket 通信原理(Android客户端和服务器以TCP&&UDP方式互通)
- 倒排索引的简单实现
- Qt OpenGL----纹理贴图
- Echarts 页面多图自适应的解决办法
- Android 四大组件之Service 的生命周期和使用
- convert doc to docx
- Android 通过Socket 和服务器通讯
- hough变换是如何检测出直线和圆的?
- 只是一个函数的问题strcpy
- 数字选择控件TimeDragPicker
- 如何开发一个产品级的Node.js 应用
- 修改XP/Win7开机动画
- Nginx系列(五. 将php-fpm注册为服务)
- Java的IO流