zoukankan      html  css  js  c++  java
  • Android开发——使用Jword生成本地word文档

    本文主要介绍如何使用Jword生成本地word文档,这里涉及到Jword的使用技巧,本文给出相应的代码,需要的朋友可以参考下。

    为什么使用Jword呢?因为IText 、Freemark在安卓平台上压根不好使呗!
    首先,Jword的网址:[Jword的网址](http://http://www.independentsoft.de/jword/index.html) 下载Jword.zip之后,解压,使用JWord/lib-android中的jword-1.0.jar放到项目中引入。
    根据Jword网址中的demo,或者压缩包中也有,来写个demo。
    下面以生成一个word表格为例,这样就ok了,测试成功,再根据自己的需求丰富一下就可以了。

    WordDocument doc = new WordDocument();

    Run run1 = new Run();
    run1.addText("Below is one table with 5 rows and 3 columns.");

    Paragraph paragraph1 = new Paragraph();
    paragraph1.add(run1);

    Cell cell1 = new Cell();

    Row row1 = new Row();
    row1.add(cell1);
    row1.add(cell1);
    row1.add(cell1); Table table1 = new Table(StandardBorderStyle.SINGLE_LINE);
    table1.setWidth(new Width(TableWidthUnit.PERCENT, 100));

    table1.add(row1);
    table1.add(row1);
    table1.add(row1);
    table1.add(row1);
    table1.add(row1);

    doc.getBody().add(paragraph1);
    doc.getBody().add(table1); try {
    doc.save(getExternalSdCardPath() + "/test.docx");
    } catch (IOException e) {
    e.printStackTrace();
    }

    本文转载自:http://www.mobile-open.com/2015/41277.html

  • 相关阅读:
    线段树优化dp(elect选择)
    gdb调试
    无参装饰器
    3.23作业
    3.22周末作业
    函数对象与闭包函数
    3.20作业
    3.19作业
    名称空间与作用域
    函数参数的使用
  • 原文地址:https://www.cnblogs.com/airnew/p/4682587.html
Copyright © 2011-2022 走看看