Tables help arrange the Word document content in rows and columns. A row is a horizontal collection of cells and a column is a vertical collection of cells. Each cell can contain multiple paragraphs and additional tables. The Syncfusion .NET Word library (DocIO) allows users to create tables with just a few lines of code in C# without relying on Microsoft Word or interop dependencies.
This example code shows how to create a table in a Word document using the Syncfusion .NET Word library with just a few lines C# code.
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
//Create a new instance of a Word document
using WordDocument document = new WordDocument();
//Add a section and a paragraph to the document
document.EnsureMinimal();
//Add a new table to the Word document
IWTable table = document.Sections[0].AddTable();
//Specify the total number of rows and columns
table.ResetCells(3, 2);
//Access each table cell and append text
table[0, 0].AddParagraph().AppendText("Item");
table[0, 1].AddParagraph().AppendText("Price($)");
table[1, 0].AddParagraph().AppendText("Apple");
table[1, 1].AddParagraph().AppendText("50");
table[2, 0].AddParagraph().AppendText("Orange");
table[2, 1].AddParagraph().AppendText("30");
//Save the Word document to FileStream
using FileStream outputStream = new FileStream("Result.docx", FileMode.Create, FileAccess.Write);
document.Save(outputStream, FormatType.Docx);
Utilize built-in table styles or create custom styles to enhance the appearance of tables.
Enable or disable special formatting options such as first column, last column, banded rows, banded columns, header row, and last row after applying a table style, providing flexibility in table design.
Set one or more rows to repeat as headers on each page in multi-page documents, ensuring consistency in table headers and improving document readability.
Control whether or not the table row content can be split across multiple pages, ensuring that the row content fits appropriately.
Check out our knowledge base articles to efficiently create and format tables in Word documents.
Knowledge base
Explore these resources for comprehensive guides, knowledge base articles, insightful blogs, and ebooks.
Product Updates
Technical Support
Yes, you can merge cells horizontally and vertically in a Word document using the .NET Word library (DocIO) in C#.
You have full control over the table’s appearance, including borders, padding, indents, and more, to customize the table’s look and feel in C#.
Adding more than 63 columns is not supported in Word documents via Microsoft Word, and an alert will appear when attempting to insert a table with more than 64 columns. DocIO follows the same limitation.
Absolutely. You can insert not just text, but also images, fields, and even other tables inside table cells programmatically.
Yes, you can format cell content with features like vertical alignment, text direction, and text wrapping using the .NET Word library (DocIO).
You can access it through the Syncfusion.DocIO.Net.Core NuGet package. Detailed code samples are available in the documentation, facilitating seamless integration.
Greatness—it’s one thing to say you have it, but it means more when others recognize it. Syncfusion® is proud to hold the following industry awards.