7 个答案:

答案 0 :(得分:3)

// Open a document.

Document doc = new Document("input.doc");

// Save document.

doc.save("output.docx");

请查看这在您的方案中是否有帮助。

披露:我在Aspose担任开发人员传播者。

答案 1 :(得分:2)

或者使用它:

XWPFDocument docx = new XWPFDocument(OPCPackage.openOrCreate(new File("hello.docx")));

XWPFWordExtractor wx = new XWPFWordExtractor(docx);

String text = wx.getText();

System.out.println("text = "+text);

答案 2 :(得分:2)

查看JODConverter以查看是否符合条款。我没有亲自使用它。

答案 3 :(得分:0)

将jodconverter-core-3.0-beta-4-sources.jar文件添加到项目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 docx

DocumentFormat docx = converter.getFormatRegistry().getFormatByExtension("docx");

docx.setStoreProperties(DocumentFamily.TEXT,

Collections.singletonMap("FilterName", "MS Word 2007 XML"));

//4)Call convert funtion in converter object

converter.convert(new File("doc/AdvancedTable.doc"), new File(

"docx/AdvancedTable.docx"), docx);

答案 4 :(得分:0)

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.OutputStream;

import com.lowagie.text.Document;

import com.lowagie.text.DocumentException;

import com.lowagie.text.Paragraph;

import com.lowagie.text.pdf.PdfWriter;

import org.apache.poi.hwpf.HWPFDocument;

import org.apache.poi.hwpf.extractor.WordExtractor;

import org.apache.poi.hwpf.usermodel.Range;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class TestCon {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

POIFSFileSystem fs = null;

Document document = new Document();

try {

System.out.println("Starting the test");

fs = new POIFSFileSystem(new FileInputStream("C:/Users/312845/Desktop/a.doc"));

HWPFDocument doc = new HWPFDocument(fs);

WordExtractor we = new WordExtractor(doc);

OutputStream file = new FileOutputStream(new File("C:/Users/312845/Desktop/test.docx"));

System.out.println("Document testing completed");

} catch (Exception e) {

System.out.println("Exception during test");

e.printStackTrace();

} finally {

// close the document

document.close();

}

}

}

答案 5 :(得分:0)

JODConvertor通过网络协议调用OpenOffice / LibreOffice。因此,它可以“在OpenOffice中执行任何操作”。这包括转换格式。但它只能像您运行的任何OpenOffice版本一样出色。我的一个文档中有一些艺术,并没有像我希望的那样转换它们。

根据谷歌代码网站v3,

不再支持JODConvertor。

要让JOD完成这项工作,你需要做一些像这样的事情

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;

@BeforeClass

public 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();

}

@AfterClass

public static void shutdownStatic() throws IOException {

officeManager.stop();

}

要实现这一点,你需要将LibreOffice作为网络服务器运行(我无法让JODConvertor的'按需运行'部分在具有LO 3.6的Windows下工作)

答案 6 :(得分:0)

使用罐子jodconverter-core-4.2.2.jar和jodconverter-local-4.2.2.jar的较新版本

String inputFile = "*.doc";

String outputFile = "*.docx";

LocalOfficeManager localOfficeManager = LocalOfficeManager.builder()

.install()

.officeHome(getDefaultOfficeHome()) //your path to openoffice

.build();

try {

localOfficeManager.start();

final DocumentFormat format

= DocumentFormat.builder()

.from(DefaultDocumentFormatRegistry.DOCX)

.build();

LocalConverter

.make()

.convert(new FileInputStream(new File(inputFile)))

.as(DefaultDocumentFormatRegistry.getFormatByMediaType("application/msword"))

.to(new File(outputFile))

.as(format)

.execute();

} catch (OfficeException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

} catch (FileNotFoundException ex) {

Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);

} finally {

OfficeUtils.stopQuietly(localOfficeManager);

}

docx命令运行Java_使用Java将DOC文件转换为DOCX相关推荐

  1. doc转docx文件会乱吗_利用python将doc文件转换为docx

    需求:最近在研究word文档的抽取,发现python中docx库只能提取以docx结尾的文件,因此需要将doc文件转换为docx. 基础知识了解 1.什么是doc? 汉语:文档(外语全称:Docume ...

  2. .doc文件转换为.docx文件

    .doc文件转换为.docx文件的python程序 #此程序调用wps来工作,如果只安装有word,则需要适当调整程序. #此程序将在待处理文件夹下新建一个名为'new'的目录,将转换后的.docx放 ...

  3. Freemark 模板生成doc文件,xml doc文件转docx 文件,docx文件转pdf文件

    freemark 模板生成doc文件,此doc文件为xml格式,无法直接转pdf 需要doc转docx文件,才能转pdf 方法1:docx4j 转 pdf 方法2: e-iceblue docx 转 ...

  4. open一个绝对路径地址 python_实例15:用Python批量转换doc文件为docx文件

    python-docx模块虽然强大,但却不能处理后缀为".doc"的word文件.如果强制读取doc文件,将会报如下错误. import docx #导入docx库doc = do ...

  5. 使用POI将doc文件转换为html

    需要的jar包有:有一些是依赖包,可以使用maven下载 doc文件转换为html文件 packagecom.gsww.sxzz.controller.service;importorg.apache ...

  6. doc文件转换html,HTML+CSS入门 如何使用POI将doc文件转换为HTML

    本篇教程介绍了HTML+CSS入门 如何使用POI将doc文件转换为HTML,希望阅读本篇文章以后大家有所收获,帮助大家HTML+CSS入门. < 需要的jar包有:有一些是依赖包,可以使用ma ...

  7. java pdf 转换 word_如何使用Java将pdf文件转换为word文件

    如何使用Java将pdf文件转换为word文件? 而且,它看起来像它一样容易吗? 解决方法: public class PDFTextReader { static String pdftoText( ...

  8. 使用java实现pdf文件转换为jpg或者png(可以批量操作、分类存放)

    使用java实现pdf文件转换为jpg或者png(可以批量操作) 使用java代码实现将pdf转换为图片格式.支持归类,支持pdf多页分页面转换存放. 需求背景:有几百个文件夹,每个文件夹里有两个pd ...

  9. 使用Aspose在Java中将Excel文件转换为HTML

    Excel电子表格可让您以表格形式存储和组织数据.也可以执行计算以及生成不同类型的图形和图表以分析数据.但是,在各种情况下,可能需要执行Excel到HTML的转换才能将工作表转换为HTML页面.例如, ...

最新文章

  1. “官宣”:程序员被正式纳入新生代农民工!
  2. Linux下MySQL5.6的修改字符集编码为UTF8(解决中文乱码问题)
  3. hive实现not in
  4. 报表引擎 - 数据模型
  5. P4097 [HEOI2013]Segment 李超线段树
  6. html5 渐变色矩形,使用HTML5画布元素的矩形渐变
  7. 苹果发布 iOS、macOS 更新,系统修复英特尔重大漏洞
  8. XSS的基本概念和原理
  9. 一、全国计算机三级数据库考试——理论知识总结(选择题)
  10. Todos案例(一)——业务分析 基本布局
  11. 如何旋转PDF页面并保存
  12. c语言实训自我总结报告,C++实训总结报告
  13. Miracle密码算法开源库(十二)分析 :mrflsh3.c
  14. abc能否构成三角形c语言,编写程序输入三角形三边a.b.c 判断abc能否构成三角形...
  15. (NO.00004)iOS实现打砖块游戏(一):素材的制作
  16. PO、VO、DO、TO、DTO、 BO、 QO、DAO、POJO
  17. Spring04:自动装配
  18. 什么是空头陷阱?(全网最全面的分析)?
  19. word打开html显示空白,word的页面显示不正常显示不出来怎么办 word怎么恢复正常页面...
  20. 【热门主题: 海贼王动漫高清壁纸图集】

热门文章

  1. e盘是否具有读写权限_轻松搭建MySQL主从复制、读写分离(双机热备)
  2. 有计算机知识,计算机基本理论基础知识总汇
  3. mysql批量写入100万数据_Mysql数据库实践操作之————批量插入数据(100万级别的数据)-阿里云开发者社区...
  4. vue中多行文本标签_vue控制多行文字展开收起的实现示例
  5. python快速排序代码_Python实现快速排序算法
  6. centos常用命令_二、Docker镜像是什么?Docker常用命令
  7. jz指令是什么意思_S7-200 SMART 运动控制指令详解-电气阿伟带小白启程
  8. 多学一招总没错吧?SpringBoot解决前后端分离的跨域问题
  9. 广度优先搜索练习之神奇的电梯
  10. Fighting_小银考呀考不过四级【递推】