DocumentUpdateTableLayout Method

Updates widths of cells and tables in the document according to their preferred widths and content. You do not need to call this method if the tables appear correct in the output document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.9.0

Syntax

public void UpdateTableLayout()

Remarks

You do not normally need to call this method as cell and table widths are maintained automatically. You can call this method before exporting to PDF (or any other fixed-page format), only in rare cases where you confirmed that tables appear incorrectly laid out in the output document. Calling this method might help to correct the output.

Examples

Shows how to preserve a table's layout when saving to .txt.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();
builder.InsertCell();
builder.Write("Cell 1");
builder.InsertCell();
builder.Write("Cell 2");
builder.InsertCell();
builder.Write("Cell 3");
builder.EndTable();

// Create a SaveOptions object to prepare this document to be saved to .txt.
TxtSaveOptions options = new TxtSaveOptions();
options.PreserveTableLayout = true;

// Previewing the appearance of the document in .txt form shows that the table will not be represented accurately.
Assert.AreEqual(0.0d, table.FirstRow.Cells[0].CellFormat.Width);
Assert.AreEqual("CCC\r\neee\r\nlll\r\nlll\r\n   \r\n123\r\n\r\n", doc.ToString(options));

// We can call UpdateTableLayout() to fix some of these issues.
doc.UpdateTableLayout();

Assert.AreEqual("Cell 1             Cell 2             Cell 3\r\n\r\n", doc.ToString(options));
Assert.AreEqual(155.0d, table.FirstRow.Cells[0].CellFormat.Width, 2f);

See Also