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

需要说明一下,JWord只有30天的试用期,过期需要购买,299欧元forever
转载于:https://my.oschina.net/u//blog/
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/215959.html原文链接:https://javaforall.net
