IRONSOFTWAREHOME
添加表格
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");
Imports IronWord
Imports IronWord.Models

' Create table
Dim table As 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 i As Integer = 1 To table.Rows.Count - 1
    table(i, 0).AddChild(New TextContent($"{i}"))
    table(i, 1).AddChild(New TextContent("---"))
    table(i, 2).AddChild(New TextContent("---"))
Next

' Create new Word document from the table
Dim doc As 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 56,401版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户