2013-09-22 96 views
-1

如何使用Java代码将存储在本地计算机中的图像添加到单词文件中。 请让我知道我可以使用的任何API。或者任何示例代码?如何使用Java将图像添加到MSWord文档中

+0

的Java = JavaScript的 – Dave

+0

的[将图像插入Java中的word文档(http://stackoverflow.com/questions/4941744/insert可能重复! -an-image-into-a-word-document-in-java) – nathanchere

回答

1

考虑的Apache POI ApachePOI

POI是操作MS office文档的API。 了解更多在这里:Duplicate ques

和一个更duplicate question

+0

谢谢..我通过他们去了 – user2794731

+0

HI ..I使用了这些链接中提到的代码,但是我收到以下错误 - 播放期间发生异常[ImagetoWord] [CRFCN0019E:脚本ImagetoWord的第53行的RationalTestScriptException - org.apache.poi.POIXMLException:org.apache.poi.openxml4j.exceptions.InvalidFormatException:包应包含内容类型部分[M1.13]。] 。 – user2794731

+0

@ Sachin Verma我用这个代码CustomXWPFDocument document = new CustomXWPFDocument(new FileInputStream(new File(“C:\\ doc1.docx”))); FileOutputStream fos = new FileOutputStream(new File(“C:\\ doc3.docx”)); String id = document.addPictureData(new FileInputStream(new File(“C:\\ a.jpg”)),Document.PICTURE_TYPE_JPEG); document.createPicture(id,document.getNextPicNameNumber(Document.PICTURE_TYPE_JPEG),64,64); (fos); fos.flush(); fos.close(); – user2794731

相关问题