Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Vertically merged cells
The example shows you how to vertically merge table's cells.
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.MergeCellType; import com.independentsoft.office.word.tables.Row; import com.independentsoft.office.word.tables.Table; import com.independentsoft.office.word.tables.TableGrid; import com.independentsoft.office.word.tables.TableGridColumn; import com.independentsoft.office.word.tables.TableWidthUnit; import com.independentsoft.office.word.tables.VerticallyMergedCell; import com.independentsoft.office.word.tables.Width; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); TableGrid tableGrid = new TableGrid(); tableGrid.getColumns().add(new TableGridColumn(498)); tableGrid.getColumns().add(new TableGridColumn(2392)); tableGrid.getColumns().add(new TableGridColumn(3600)); tableGrid.getColumns().add(new TableGridColumn(1800)); tableGrid.getColumns().add(new TableGridColumn(1186)); VerticallyMergedCell verticallyMergedCell = new VerticallyMergedCell(MergeCellType.RESTART); Cell cell11 = new Cell(); cell11.setVerticallyMergedCell(verticallyMergedCell); cell11.setWidth(new Width(TableWidthUnit.POINT, 498)); Cell cell12 = new Cell(); cell11.setWidth(new Width(TableWidthUnit.POINT, 2392)); Cell cell13 = new Cell(); cell11.setWidth(new Width(TableWidthUnit.POINT, 3600)); Cell cell14 = new Cell(); cell11.setWidth(new Width(TableWidthUnit.POINT, 1800)); Cell cell15 = new Cell(); cell11.setWidth(new Width(TableWidthUnit.POINT, 1186)); Row row1 = new Row(); row1.add(cell11); row1.add(cell12); row1.add(cell13); row1.add(cell14); row1.add(cell15); Cell cell21 = new Cell(); cell21.setVerticallyMergedCell(new VerticallyMergedCell()); cell21.setWidth(new Width(TableWidthUnit.POINT, 498)); Cell cell22 = new Cell(); cell22.setGridSpan(4); cell22.setWidth(new Width(TableWidthUnit.POINT, 8978)); Row row2 = new Row(); row2.add(cell21); row2.add(cell22); Table table1 = new Table(StandardBorderStyle.SINGLE_LINE); table1.setGrid(tableGrid); table1.add(row1); table1.add(row2); 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*