Back to Devexpress

How to: Create a Table with Fixed Column Width

officefileapi-117410-word-processing-document-api-examples-tables-how-to-create-a-table-with-fixed-column-width.md

latest2.8 KB
Original Source

How to: Create a Table with Fixed Column Width

  • Sep 19, 2023

To create a table with fixed column widths, specify the following settings:

PropertyValue
For the table set the Table.TableLayoutTableLayoutType.Fixed
For the table set the Table.PreferredWidthTypeWidthType.Fixed
For each cell set the TableCell.PreferredWidthTypeWidthType.Fixed
For each cell set the TableCell.PreferredWidthA floating point value specifying the cell width measured in document units of measurement determined by the Document.Unit property.

View Example

csharp
using XtraRichEdit.API.Native;
using DevExpress.Office.Utils;

using (var wordProcessor = new richEditDocumentServer())
{
    Document document = wordProcessor.Document;
    Table table = document.Tables.Create(document.Range.Start, 3, 3);

    table.TableAlignment = TableRowAlignment.Center;
    table.TableLayout = TableLayoutType.Fixed;
    table.PreferredWidthType = WidthType.Fixed;
    table.PreferredWidth = .Units.InchesToDocumentsF(4f);

    table.Rows[1].HeightType = HeightType.Exact;
    table.Rows[1].Height = Units.InchesToDocumentsF(0.8f);

    table[1, 1].PreferredWidthType = WidthType.Fixed;
    table[1, 1].PreferredWidth = Units.InchesToDocumentsF(1.5f);

    table.MergeCells(table[1, 1], table[2, 1]);
}
vb
Imports XtraRichEdit.API.Native
Imports DevExpress.Office.Utils

Using wordProcessor = New richEditDocumentServer()
    Dim document As Document = wordProcessor.Document
    Dim table As Table = document.Tables.Create(document.Range.Start, 3, 3)

    table.TableAlignment = TableRowAlignment.Center
    table.TableLayout = TableLayoutType.Fixed
    table.PreferredWidthType = WidthType.Fixed
    table.PreferredWidth =.Units.InchesToDocumentsF(4F)

    table.Rows(1).HeightType = HeightType.Exact
    table.Rows(1).Height = Units.InchesToDocumentsF(0.8F)

    table(1, 1).PreferredWidthType = WidthType.Fixed
    table(1, 1).PreferredWidth = Units.InchesToDocumentsF(1.5F)

    table.MergeCells(table(1, 1), table(2, 1))
End Using