Java byteArray[] to docx

China☆狼群 提交于 2019-12-13 05:16:45

问题


doc file in byte[] type. Is it possible to convert it from byte[] into .docx file.

tried just change file extension programilly but it does not work. any suggestions?

I generate report using BiRT eclipse code of saving doc:

options = new RenderOptionBase();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
options.setOutputStream(bos);
options.setOutputFormat("doc");
if(parameters != null){
    task.setParameterValues(parameters);
}
task.setRenderOption(options);
task.run();

return bos.toByteArray()

//IRunAndRenderTask task;

problem is that we use BIRT 3.7 which not support DocxRenderOption


回答1:


Take a look at Aspose.Words for Java -- http://www.aspose.com/java/word-component.aspx

It has really good doc too -- http://www.aspose.com/docs/display/wordsjava/load+or+create+a+document

Code will be as simple as

// Open a document.

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

// Save document.

doc.save("output.docx");

Step1: save the doc file Step2: using this lib convert the file and save as docx file.



来源:https://stackoverflow.com/questions/25890776/java-bytearray-to-docx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!