ComponentOne Word for WinForms
Working with Word for WinForms / Advanced Level Working / Inserting Table
In This Topic
    Inserting Table
    In This Topic

    Table is used in word documents to present data in a well formatted form with the help of rows and columns. It is a very common practice to use tables in word documents to represent formatted data in rows and columns. Word component enables you to add table to your document using RtfTable class to create a table and RtfParagraph class to insert content in table.

    Following code adds a table to a word document:

    Dim rows As Integer = 4
    Dim cols As Integer = 2
    Dim table As New RtfTable(rows, cols)
    For row As Integer = 0 To rows - 1
            For col As Integer = 0 To cols - 1
                    Dim paragraph As New RtfParagraph()
                    paragraph.Content.Add(New RtfString(String.Format("table cell {0}:{1}.", row, col)))
    int rows = 4;
    int cols = 2;
    RtfTable table = new RtfTable(rows, cols);
    for (int row = 0; row < rows; row++)
            for (int col = 0; col < cols; col++)
            RtfParagraph paragraph = new RtfParagraph();
            paragraph.Content.Add(new RtfString(string.Format("table cell {0}:{1}.", row, col)));