This tutorial lists two different ways to create table in Word document using C#. We will first create table in Word using C# with the help of an Aspose DocumentBuilder and later create Word table using C# directly in Word document object model (DOM).
Steps to Create Table in Word Document using C#
- Reference the Aspose.Words for .NET package from NuGet in solution
- Import Aspose.Words and Aspose.Words.Tables namespaces
- Create DocumentBuilder or Table class instance
- Use InsertCell or Table.Rows.Cells.Add method to add cells in table row
- Use DocumentBuilder.Write or Cell.AppendChild method to insert paragraph text
- Create multiple rows in table and finish table creation in Word document
- Save as Word document with table to DOCX format on disk
The following Aspose DocumentBuilder code example can be used in .NET application for C# Word table creation.
Code to Create Table in Word Document using C#
Essentially, this create table Word C# app enables you to insert a table in Word document. It first adds two cells in the first table row and later writes text content in first cell and then add image to Word C# last cell.
Code to Create Word Table using C# (DOM Classes)
The above Aspose Word create table C# code example just presents an alternate approach for adding a table element in Word document object model using Table, Row, Cell and Paragraph classes.