//辅助 03 写入文件
public static void writeFile(String content, String path) {    FileOutputStream fos = null;    BufferedWriter bw = null;    try {    File file = new File(path);    fos = new FileOutputStream(file);    bw = new BufferedWriter(new OutputStreamWriter(fos,"utf-8"));    bw.write(content);    } catch (FileNotFoundException fnfe) {    fnfe.printStackTrace();    } catch (IOException ioe) {    ioe.printStackTrace();    } finally {    try {    if (bw != null)    bw.close();    if (fos != null)    fos.close();    } catch (IOException ie) {    ie.printStackTrace();}    }    }//将Doc文件 转成html 并输出public static void convert2Html(String fileName, String outPutFile)    throws TransformerException, IOException,   ParserConfigurationException {System.out.println("outPutFile========="+outPutFile);HWPFDocument wordDocument = new HWPFDocument(new FileInputStream(fileName));//WordToHtmlUtils.loadDoc(new FileInputStream(inputFile));    WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(    DocumentBuilderFactory.newInstance().newDocumentBuilder()    .newDocument());    wordToHtmlConverter.setPicturesManager( new PicturesManager()    {    public String savePicture( byte[] content,    PictureType pictureType, String suggestedName,    float widthInches, float heightInches )    {    return suggestedName;    }    } );    wordToHtmlConverter.processDocument(wordDocument);    //save pictures    List pics=wordDocument.getPicturesTable().getAllPictures();    if(pics!=null){    for(int i=0;i<pics.size();i++){    Picture pic = (Picture)pics.get(i);    System.out.println();    try {
//                          pic.writeImageContent(new FileOutputStream("D:/UC/"
//                                  + pic.suggestFullFileName()));   pic.writeImageContent(new FileOutputStream("E:\\workspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\wordConvertHtml\\upload\\" + pic.suggestFullFileName()));    } catch (FileNotFoundException e) {    e.printStackTrace();    }      }    }    Document htmlDocument = wordToHtmlConverter.getDocument();    ByteArrayOutputStream out = new ByteArrayOutputStream();    DOMSource domSource = new DOMSource(htmlDocument);    StreamResult streamResult = new StreamResult(out);    TransformerFactory tf = TransformerFactory.newInstance();    Transformer serializer = tf.newTransformer();    serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");    serializer.setOutputProperty(OutputKeys.INDENT, "yes");    serializer.setOutputProperty(OutputKeys.METHOD, "html");    serializer.transform(domSource, streamResult);    out.close();
//              String caselsh = fileName.substring(0,fileName.lastIndexOf("."));
//              writeFile(new String(out.toByteArray()), caselsh+".html");    writeFile(new String(out.toByteArray()), outPutFile); }  

07格式转:

public static void word2007ToHtml2(String path,String filename ) throws FileNotFoundException, IOException{
//          String filepath = "D:\\UC\\";System.out.println("filename>>>"+filename);String sourceFileName =path+"\\"+filename; String caselsh = filename.substring(0,filename.lastIndexOf(".")); String targetFileName = path+"\\"+caselsh+".html"; String imagePathStr =  path+"/image/word/media/";   OutputStreamWriter outputStreamWriter = null;System.out.println(sourceFileName+">>sourceFileName");System.out.println(targetFileName+">>targetFileName");System.out.println(imagePathStr+">>imagePathStr");try { XWPFDocument document = new XWPFDocument(new FileInputStream(sourceFileName)); XHTMLOptions options = XHTMLOptions.create(); // 存放图片的文件夹 options.setExtractor(new FileImageExtractor(new File(imagePathStr))); // html中图片的路径
//            options.URIResolver(new BasicURIResolver("image")); options.URIResolver(new BasicURIResolver(imagePathStr));outputStreamWriter = new OutputStreamWriter(new FileOutputStream(targetFileName), "utf-8"); XHTMLConverter xhtmlConverter = (XHTMLConverter) XHTMLConverter.getInstance(); xhtmlConverter.convert(document, outputStreamWriter, options); } finally { if (outputStreamWriter != null) { outputStreamWriter.close(); } }}
//省略了SpringMVC 以及 jsp界面上传控件

所需的jar包:

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>wordConvertHtml</groupId><artifactId>wordConvertHtml</artifactId><version>0.0.1-SNAPSHOT</version><packaging>pom</packaging><name>wordConvertHtml Maven Webapp</name><!-- FIXME change it to the project's website --><url>http://www.example.com</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-scratchpad</artifactId> <version>3.14</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.14</version> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>xdocreport</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.14</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>ooxml-schemas</artifactId> <version>1.3</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.directory.studio/org.apache.commons.io -->
<dependency><groupId>org.apache.directory.studio</groupId><artifactId>org.apache.commons.io</artifactId><version>2.4</version>
</dependency><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.10</version>
</dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-collections4</artifactId><version>4.1</version>
</dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.2.2</version>
</dependency>
<dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>1.4</version>
</dependency>
<dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version>
</dependency></dependencies><build><finalName>wordConvertHtml</finalName><pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --><plugins><plugin><artifactId>maven-clean-plugin</artifactId><version>3.1.0</version></plugin><!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --><plugin><artifactId>maven-resources-plugin</artifactId><version>3.0.2</version></plugin><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.0</version></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.22.1</version></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>3.2.2</version></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.5.2</version></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.8.2</version></plugin></plugins></pluginManagement></build><modules><module>?</module></modules>
</project>

用Poi 转word docx 跟 doc 格式相关推荐

  1. Word处理控件Aspose.Words功能演示:在 Python 中将 Word DOCX 或 DOC 转换为 PDF

    Word 到PDF是最流行和执行最广泛的文档转换之一.DOCX或DOC文件在打印或共享之前会转换为 PDF 格式.在本文中,我们将在 Python 中自动将 Word 转换为 PDF.步骤和代码示例将 ...

  2. word文档doc格式转换成docx

    把doc格式转换成docx jar包下载 //把doc格式转换成docx//导入 Spire.Doc.jarDocument d = new Document("F:\\**\\**\\云想 ...

  3. 批量将 PDF 转为 Word 文档,支持 Docx、Doc 格式

    概要:PDF 和 Word 这两种格式是非常常见的,并且相互之间也经常需要进行格式转化.Word 转 PDF是非常容易就能做到的,但是 PDF 转 Word 就经常会碰到各种各样的问题,比如格式错乱. ...

  4. docx poi 原理,如何从Apache POI知道文件是.docx还是.doc格式

    I know we can get it done by extension or by mime type, do we have any other way through which we ca ...

  5. apache poi 修改docx表格_JAVA poi对word.docx文件的修改

    之前老用poi处理excel,近期看了一下处理word,同时也学习了一下,根据网上的资料写了一个读取word.docx 文档并在word中加入自定义的文本以及图片. 其中poi中有2中word的处理一 ...

  6. 使用POI读写word docx文件

    目录 1     读docx文件 1.1     通过XWPFWordExtractor读 1.2     通过XWPFDocument读 2     写docx文件 2.1     直接通过XWPF ...

  7. 【Word】下载的word文档(doc格式)编辑后出现(同文件名.files)的文件夹--解决办法

    文章目录 1. 此处为标题所述情况,解决办法见下一标题 2. 解决办法--如何确保修改文件后,不出现[原文件--更改.files]的文件夹 1. 此处为标题所述情况,解决办法见下一标题 如图1-创建原 ...

  8. 让Word 2007默认文档保存格式为Word 2003的DOC格式

    Microsoft Office 2007已经正式发布了,相信已经有不少朋友在使用这款功能超强的办公软件了!众所周知,Office 2007的默认文档格式采用了开放式的XML文档格式(后缀多了个X), ...

  9. docx poi 原理_使用POI读写word docx文件

    目录 1     读docx文件 1.1     通过XWPFWordExtractor读 1.2     通过XWPFDocument读 2     写docx文件 2.1     直接通过XWPF ...

最新文章

  1. 学习 Linux,101: 引导系统
  2. Win2003的DHCP服务器无法提供服务怎么办?
  3. python日历提醒_如何通过python发送日历邮件(ics)
  4. 数据库alter用法总结
  5. VUE系列-Vue中组件的应用(三)
  6. 论Postgres的“已提交的而且 xmin’比当前事务的XID小的记录对当前事务才是可见的”...
  7. bzoj2190: [SDOI2008]仪仗队(欧拉)
  8. awk去除行首行尾空格
  9. java的package需要大写吗,java 数字转大写的小程序
  10. 淘宝API 拍立淘图片搜索接口
  11. Redis高频面试题完整版
  12. 公众号识别用户进入发送信息
  13. Zhong__Jenkins安装和使用
  14. 查看进程名称 linux,在Linux系统服务器按名称查找进程的命令
  15. SOLIDWORKS如何正确使用焊件及材料切割清单
  16. Lucene4.3开发之第五步之融丹筑基(五)
  17. 压缩工具WinRAR推出免费的中国个人版
  18. Oracle SQL到DB2 SQL移植解决方案
  19. 高防服务器对ip有影响吗,高防服务器与高防IP的区别和联系
  20. App复杂动画实现——Rive保姆级教程 | 京东云技术团队

热门文章

  1. Kubernetes Kubeadm init 与 join 原理分析
  2. 教程7--Schemas和客户端库
  3. java8教程-并发编程
  4. 秋叶收藏集, 动态规划 leetcode LCP 19
  5. 易乐游装在云服务器_新手搭建云服务器详细过程
  6. zoho邮箱收信服务器,配置邮件交付 - Zoho Mail 设置
  7. 李佳琦以特殊人才落户上海,“带货一哥”即将成为“新上海人”
  8. HiveSQL中级进阶常用技巧
  9. 网络抖动多少ms算正常_网络延迟多少ms才算正常
  10. C#中TransactionScope的使用小结