日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

poi xwpf 转换成 html,Apache POI创建的docx文档无法转化成html

發(fā)布時間:2024/10/5 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poi xwpf 转换成 html,Apache POI创建的docx文档无法转化成html 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

當我通過word軟件創(chuàng)建文檔的時候

FileInputStream fileInputStream = new FileInputStream(sourceFileName);

//當你確定該文件可信任時使用該方法,避免大文件被誤認為是zip炸彈,實際上不推薦上傳大文件,會導致資源消耗過快

// ZipSecureFile.setMinInflateRatio(-1.0d);

XWPFDocument document = new XWPFDocument(fileInputStream);

System.out.println(document.getStyles());

XHTMLOptions options = XHTMLOptions.create().indent(4);

options.setExtractor(new FileImageExtractor(new File(imgPath)));

options.URIResolver(new BasicURIResolver(imgPath));

ByteArrayOutputStream baos = new ByteArrayOutputStream();

XHTMLConverter.getInstance().convert(document,baos,options);

baos.close();

content = baos.toString();

上面這段代碼運行是正常的

但是當我通過apache poi創(chuàng)建docx文檔的時候,卻會提示

Exception in thread "main" org.apache.poi.xwpf.converter.core.XWPFConverterException: java.lang.IllegalStateException: Expecting one Styles document part, but found 0

at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.convert(XHTMLConverter.java:77)

at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.doConvert(XHTMLConverter.java:63)

at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.doConvert(XHTMLConverter.java:38)

at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)

at WordToHtml.WordToHtml.docToHtml(WordToHtml.java:112)

at WordToHtml.WordToHtml.main(WordToHtml.java:42)

Caused by: java.lang.IllegalStateException: Expecting one Styles document part, but found 0

at org.apache.poi.xwpf.usermodel.XWPFDocument.getStyle(XWPFDocument.java:461)

at org.apache.poi.xwpf.converter.core.styles.XWPFStylesDocument.(XWPFStylesDocument.java:190)

at org.apache.poi.xwpf.converter.xhtml.internal.styles.CSSStylesDocument.(CSSStylesDocument.java:100)

at org.apache.poi.xwpf.converter.xhtml.internal.XHTMLMapper.createStylesDocument(XHTMLMapper.java:147)

at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.(XWPFDocumentVisitor.java:159)

at org.apache.poi.xwpf.converter.xhtml.internal.XHTMLMapper.(XHTMLMapper.java:137)

at org.apache.poi.xwpf.converter.xhtml.XHTMLConverter.convert(XHTMLConverter.java:72)

... 5 more

我創(chuàng)建文檔的代碼如下:

package WordToHtml;

import org.apache.poi.xwpf.usermodel.ParagraphAlignment;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.File;

import java.io.FileOutputStream;

public class CreateDocx {

public static void main(String[] args) throws Exception {

XWPFDocument document = new XWPFDocument();

FileOutputStream out = new FileOutputStream(new File("C:\\demo\\test.docx"));

XWPFParagraph firstParagraph = document.createParagraph();

firstParagraph.setAlignment(ParagraphAlignment.LEFT);

for (int i = 0;i<=50;i++) {

XWPFRun run = firstParagraph.createRun();

run.setText("Java POI 生成word文件。"+i);

run.addBreak();

run.setColor("696969");

}

firstParagraph.setStyle("");

//把word文檔寫到輸出流

document.write(out);

}

}

請問這個是該怎么解決?

總結

以上是生活随笔為你收集整理的poi xwpf 转换成 html,Apache POI创建的docx文档无法转化成html的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。