版權聲明:本文爲HaiyuKing原創文章,轉載請註明出處!html
嘗試的方案包括如下幾種:java
參考資料:《FreemarkerJavaDemo【Android將表單數據生成Word文檔的方案之一(基於freemarker2.3.28,只能java生成)】》spa
參考資料:《PoiDemo【Android將表單數據生成Word文檔的方案之二(基於Poi4.0.0)】》【目前使用這個】code
《PoiDocxDemo【Android將表單數據生成Word文檔的方案之二(基於Poi4.0.0),目前只能java生成】》htm
參考資料:《官網》blog
demo中的替換文本用法很簡單:圖片
import com.independentsoft.office.word.WordDocument; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument("c:\\test\\input.docx"); doc.replace("[CustomerID]", "12345"); doc.replace("[CustomerName]","John Smith"); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }