Word for WinForms
表の挿入
Word for WinForms の操作 > 上級レベルの操作 > 表の挿入

表は、Word ドキュメントでデータをいくつかの行と列に整えて表示するために使用されます。Word ドキュメントで、データをいくつかの行と列に整えて表示するために表を使用することはごく一般的なことです。Word コンポーネントを使用すると Word ドキュメントに表を追加できます。それには RtfTable クラスを使用して表を作成し、RtfParagraph クラスを使用して表にコンテンツを挿入します。

次のコードは、Word ドキュメントに表を追加します。

Dim rows As Integer = 4
Dim cols As Integer = 2
Dim table As New RtfTable(rows, cols)
C1Word.Add(table)
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)))
                table.Rows(row).Cells(col).Content.Add(paragraph)
        Next
Next
int rows = 4;
int cols = 2;
RtfTable table = new RtfTable(rows, cols);
C1Word.Add(table);
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)));
        table.Rows[row].Cells[col].Content.Add(paragraph);
        }
}