簡體   English   中英

使用Apache POI將圖像插入android Java中的.doc文件

[英]insert image to .doc file in android Java using Apache POI

我正在嘗試將圖像寫入android中的.doc文件。 我搜索了很多東西,但找不到任何幫助。 我得到的一個提示是Apache POI庫。 我也進行了研究,但無法獲得描述問題的任何方法。 我知道如何創建該文件,這是其文檔中執行此操作的代碼

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();

   }

}

但是我如何將圖像插入該文件。 請幫忙。 任何幫助將非常感激。 謝謝

首先確定所需的.doc或.docx(知道區別)。您詢問了.doc格式的問題,但您的代碼說的是.docx(.docx的XWPFDocument)

截至目前,尚無法使用HWPF將圖像添加到.doc中(如果我輸入錯了,請糾正我)。

如果要尋找.docx(XWPF), 請https://poi.apache.org/apidocs/

在XWPFDocument和XWPFRun中查找addPicture及其示例

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM