Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Create table
The following example shows you how to create a table.
import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.StandardBorderStyle; import com.independentsoft.office.word.WordDocument; import com.independentsoft.office.word.tables.Cell; import com.independentsoft.office.word.tables.Row; import com.independentsoft.office.word.tables.Table; import com.independentsoft.office.word.tables.TableWidthUnit; import com.independentsoft.office.word.tables.Width; public class Example { public static void main(String[] args) { try { 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); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*