Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JODF
>
Tutorial
> Insert table
The following example shows you how to insert a table.
import com.independentsoft.office.odf.Cell; import com.independentsoft.office.odf.Paragraph; import com.independentsoft.office.odf.Row; import com.independentsoft.office.odf.Table; import com.independentsoft.office.odf.TextDocument; public class Example { public static void main(String[] args) { try { TextDocument doc = new TextDocument(); Cell cell1 = new Cell("test1"); Cell cell2 = new Cell("test2"); Cell cell3 = new Cell("test3"); Row row1 = new Row(); row1.getCells().add(cell1); row1.getCells().add(cell2); row1.getCells().add(cell3); Table table1 = new Table(); table1.getRows().add(row1); table1.getRows().add(row1); table1.getRows().add(row1); table1.getRows().add(row1); table1.getRows().add(row1); Paragraph p1 = new Paragraph(); p1.add("Below is a table:"); Paragraph p2 = new Paragraph(); doc.getBody().add(p1); doc.getBody().add(p2); doc.getBody().add(table1); doc.save("c:\\test\\output.odt", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*