添加表格
using IronWord;
using IronWord.Models;

// Create table
Table table = new Table(5, 3);

// Apply styling
table.Zebra = new ZebraColor("FFFFFF", "dddddd");

// Populate table
table[0, 0] = new TableCell(new TextContent("Number"));
table[0, 1] = new TableCell(new TextContent("First Name"));
table[0, 2] = new TableCell(new TextContent("Last Name"));
for (int i = 1; i < table.Rows.Count; i++)
{
    table[i, 0].AddChild(new TextContent($"{i}"));
    table[i, 1].AddChild(new TextContent($"---"));
    table[i, 2].AddChild(new TextContent($"---"));
}

// Create new Word document from the table
WordDocument doc = new WordDocument(table);

// Export Word document
doc.SaveAs("Document.docx");
NuGet Download
PM > Install-Package IronWord
添加表格

添加表格

表格是由行和列排列的单元格组成的网格。 这是一项基本功能,可让您以结构化的方式组织和呈现信息。 表格中行和列的每次交点称为一个单元格。 表格通常用于各种用途,例如创建日程表、整理数据和整齐地排列内容。

要使用IronWord添加表格,首先通过提供行数和列数来实例化一个表格。 根据您的需求自定义整个表格样式。 使用[row, column]格式访问表格的每个单元格。 有了这个,您可以相应地设置每个单元格的样式,并向单元格添加多个文档元素,例如shape。 表格对象设置完成后,即可用于创建新的 Word 文档。

学习如何使用 IronWord 在 Word 中添加表格
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 61,140版本:2026.11刚刚发布