2015-04-03 61 views
0

我试图在android中将图像写入.doc文件。我搜索了很多,我找不到任何帮助。我有这样一个提示是Apache POI库。我也研究过它,我无法得到任何描述我的问题的方法。我知道如何创建一个文件,这里是代码做到这一点从它的文档在Android Java中使用Apache POI插入图像到.doc文件

import java.io.File; 
import java.io.FileOutputStream; 
import org.apache.poi.xwpf.usermodel.XWPFDocument; 

public class CreateDocument 
{ 
    public static void main(String[] args)throws Exception 
    { 
    //Blank Document 
    XWPFDocument document= new XWPFDocument(); 
    //Write the Document in file system 
    FileOutputStream out = new FileOutputStream(
    new File("createdocument.docx")); 
    document.write(out); 
    out.close(); 

    } 

}

但我怎么可以插入图片到该文件。请帮忙。任何帮助将非常感激。由于

+1

的Apache POI网站,这提供了范例。 http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleImages.java – mkrakhin 2015-04-03 14:12:41

回答

0

首先决定你想要什么.doc或.DOCX(知道其中的差别) 你问.doc格式的问题,但你的代码表示的.docx(XWPFDocument为.DOCX)

截至目前已经有没有办法使用HWPF将图像添加到.doc中(如果我错了,请纠正我)。

如果寻找的.docx(XWPF)然后https://poi.apache.org/apidocs/

找给AddPicture在XWPFDocument和XWPFRun 和示例相同

http://svn.apache.org/repos/asf/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/

相关问题