wblinych的gravatar头像
wblinych 2017-12-06 16:15:08

把ckfinder的html内容放到docx里面呢?

我在项目中遇到一个问题,在ckfinder读取出来的内容,现在需要把他放到docx里面。请问该如何解决呢?

我这里想不到任何好用的方法。

有想过先把这段html代码生成一个doc然后去进行读取这个doc里面的内容,一个一个插入到docx中,但是生成的doc文件不能读取。

// 生成临时文件名称
String fileName = "a.doc";
String content = "<html>" +
        "<div style=\"text-align: center\"><span style=\"font-size: 28px\"><span style=\"font-family: 黑体\">" +
        "啊啊啊啊啊啊啊啊<br/><br/></span></span></div></html>";
byte b[] = content.getBytes();
POIFSFileSystem poifs = new POIFSFileSystem();
InputStream bais = new ByteArrayInputStream(b);
DirectoryEntry directory = poifs.getRoot();
DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
FileOutputStream ostream = new FileOutputStream(path+ fileName);
poifs.writeFilesystem(ostream);
bais.close();
ostream.close();
System.out.println(path+fileName);
File file = new File(path + fileName);
b = Files.readAllBytes(Paths.get(path + fileName));
InputStream is = new ByteArrayInputStream(b);
HWPFDocument document1 = new HWPFDocument(is);//执行到这一步报错。

//报错信息。

org.apache.poi.EncryptedDocumentException: Cannot process encrypted word file

at org.apache.poi.hwpf.model.FileInformationBlock.<init>(FileInformationBlock.java:77)

at org.apache.poi.hwpf.HWPFDocumentCore.<init>(HWPFDocumentCore.java:155)

at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:218)

at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:186)

at org.apache.poi.hwpf.HWPFDocument.<init>(HWPFDocument.java:174)

at POITest.HtmlToWord(POITest.java:51)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)

at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)

at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

所有回答列表(0)
相关问答
最近浏览
Call Me 采先森  LV10 2018年8月2日
744057173  LV5 2017年12月15日
mySong  LV11 2017年12月6日
丶唯神能恕  LV4 2017年12月6日
最代码官方  LV167 2017年12月6日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友