endRow method
endRow()
Ends a table row in the document.
endRow()
Remarks
Call DocumentBuilder.endRow() to end a table row. If you call DocumentBuilder.insertCell() immediately after that, then the table continues on a new row.
Use the DocumentBuilder.rowFormat property to specify row formatting.
Returns
The row node that was just finished.
Examples
Shows how to build a table with custom borders.
let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);
builder.startTable();
// Setting table formatting options for a document builder
// will apply them to every row and cell that we add with it.
builder.paragraphFormat.alignment = aw.ParagraphAlignment.Center;
builder.cellFormat.clearFormatting();
builder.cellFormat.width = 150;
builder.cellFormat.verticalAlignment = aw.Tables.CellVerticalAlignment.Center;
builder.cellFormat.shading.backgroundPatternColor = "#ADFF2F";
builder.cellFormat.wrapText = false;
builder.cellFormat.fitText = true;
builder.rowFormat.clearFormatting();
builder.rowFormat.heightRule = aw.HeightRule.Exactly;
builder.rowFormat.height = 50;
builder.rowFormat.borders.lineStyle = aw.LineStyle.Engrave3D;
builder.rowFormat.borders.color = "#FFA500";
builder.insertCell();
builder.write("Row 1, Col 1");
builder.insertCell();
builder.write("Row 1, Col 2");
builder.endRow();
// Changing the formatting will apply it to the current cell,
// and any new cells that we create with the builder afterward.
// This will not affect the cells that we have added previously.
builder.cellFormat.shading.clearFormatting();
builder.insertCell();
builder.write("Row 2, Col 1");
builder.insertCell();
builder.write("Row 2, Col 2");
builder.endRow();
// Increase row height to fit the vertical text.
builder.insertCell();
builder.rowFormat.height = 150;
builder.cellFormat.orientation = aw.TextOrientation.Upward;
builder.write("Row 3, Col 1");
builder.insertCell();
builder.cellFormat.orientation = aw.TextOrientation.Downward;
builder.write("Row 3, Col 2");
builder.endRow();
builder.endTable();
doc.save(base.artifactsDir + "DocumentBuilder.InsertTable.docx");
Shows how to build a formatted 2x2 table.
let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);
let table = builder.startTable();
builder.insertCell();
builder.cellFormat.verticalAlignment = aw.Tables.CellVerticalAlignment.Center;
builder.write("Row 1, cell 1.");
builder.insertCell();
builder.write("Row 1, cell 2.");
builder.endRow();
// While building the table, the document builder will apply its current RowFormat/CellFormat property values
// to the current row/cell that its cursor is in and any new rows/cells as it creates them.
expect(table.rows.at(0).cells.at(0).cellFormat.verticalAlignment).toEqual(aw.Tables.CellVerticalAlignment.Center);
expect(table.rows.at(0).cells.at(1).cellFormat.verticalAlignment).toEqual(aw.Tables.CellVerticalAlignment.Center);
builder.insertCell();
builder.rowFormat.height = 100;
builder.rowFormat.heightRule = aw.HeightRule.Exactly;
builder.cellFormat.orientation = aw.TextOrientation.Upward;
builder.write("Row 2, cell 1.");
builder.insertCell();
builder.cellFormat.orientation = aw.TextOrientation.Downward;
builder.write("Row 2, cell 2.");
builder.endRow();
builder.endTable();
// Previously added rows and cells are not retroactively affected by changes to the builder's formatting.
expect(table.rows.at(0).rowFormat.height).toEqual(0);
expect(table.rows.at(0).rowFormat.heightRule).toEqual(aw.HeightRule.Auto);
expect(table.rows.at(1).rowFormat.height).toEqual(100);
expect(table.rows.at(1).rowFormat.heightRule).toEqual(aw.HeightRule.Exactly);
expect(table.rows.at(1).cells.at(0).cellFormat.orientation).toEqual(aw.TextOrientation.Upward);
expect(table.rows.at(1).cells.at(1).cellFormat.orientation).toEqual(aw.TextOrientation.Downward);
doc.save(base.artifactsDir + "DocumentBuilder.BuildTable.docx");
Shows how to merge table cells vertically.
let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);
// Insert a cell into the first column of the first row.
// This cell will be the first in a range of vertically merged cells.
builder.insertCell();
builder.cellFormat.verticalMerge = aw.Tables.CellMerge.First;
builder.write("Text in merged cells.");
// Insert a cell into the second column of the first row, then end the row.
// Also, configure the builder to disable vertical merging in created cells.
builder.insertCell();
builder.cellFormat.verticalMerge = aw.Tables.CellMerge.None;
builder.write("Text in unmerged cell.");
builder.endRow();
// Insert a cell into the first column of the second row.
// Instead of adding text contents, we will merge this cell with the first cell that we added directly above.
builder.insertCell();
builder.cellFormat.verticalMerge = aw.Tables.CellMerge.Previous;
// Insert another independent cell in the second column of the second row.
builder.insertCell();
builder.cellFormat.verticalMerge = aw.Tables.CellMerge.None;
builder.write("Text in unmerged cell.");
builder.endRow();
builder.endTable();
doc.save(base.artifactsDir + "CellFormat.verticalMerge.docx");
See Also
- module Aspose.Words
- class DocumentBuilder