欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android根据word模板文档将表单数据生成word文档的方案整理

程序员文章站 2022-07-09 20:09:28
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 尝试的方案包括以下几种: freemarker 只能在java项目上运行,无法在Android项目上运行; 参考资料:《FreemarkerJavaDemo【Android将表单数据生成Word文档的方案之一(基于freemarke ......

版权声明:本文为haiyuking原创文章,转载请注明出处!

前言

尝试的方案包括以下几种:

freemarker

  • 只能在java项目上运行,无法在android项目上运行;

参考资料:《freemarkerjavademo【android将表单数据生成word文档的方案之一(基于freemarker2.3.28,只能java生成)】

poi

  • 解析doc文件可以在android项目上运行;
  • 解析docx文件只能在java项目上运行,无法在android项目上运行;
  • 暂时未实现替换图片功能;

参考资料:《poidemo【android将表单数据生成word文档的方案之二(基于poi4.0.0)】》【目前使用这个

poidocxdemo【android将表单数据生成word文档的方案之二(基于poi4.0.0),目前只能java生成】

jword

  • 即支持java项目也支持android项目;
  • 需要花钱(jword只有30天的试用期,过期需要购买,299欧元forever~~2129.1491人民币元)

 参考资料:《》

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