安卓平台 使用Jword生成word文档到本地【亲测成功】

为何使用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();
    }

word截图

须要说明一下,JWord只有30天的试用期,过时须要购买,299欧元foreverhtml

相关文章
相关标签/搜索