Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JODF
>
Tutorial
> Create header row
The following example shows you how to create table header row.
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 headerCell1 = new Cell("Header 1"); Cell headerCell2 = new Cell("Header 2"); Cell headerCell3 = new Cell("Header 3"); Row headerRow = new Row(); headerRow.setHeader(true); headerRow.getCells().add(headerCell1); headerRow.getCells().add(headerCell2); headerRow.getCells().add(headerCell3); 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.getHeaderRows().add(headerRow); for (int i = 0; i < 200; i++) { table1.getRows().add(row1); } Paragraph p1 = new Paragraph(); p1.add("Below is a table:"); doc.getBody().add(p1); doc.getBody().add(new Paragraph()); //empty paragraph doc.getBody().add(new Paragraph()); //empty paragraph 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*