IronWord 开始 Getting Started with IronWord Curtis Chau 已更新:六月 10, 2025 Download IronWord NuGet 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English IronWord: Word Document Library for .NET IronWord is a Word document library developed by Iron Software. IronWord excels in providing robust functionality for working with Word documents in .NET applications. Load, Manipulate, and Save Word and Docx Documents. PageSetup: Configuring paper size, page orientation, margins, and background color. TextRun: Handling text content, styles, splitting, appending text, and adding images. TextStyle: Managing font family, size, color, bold, italic, strikethrough, underline, superscript, and subscript. Paragraph: Adding text runs, images, shapes, setting styles, alignments, bullets, and numbering lists. Table: Manipulating table structure, including adding rows, getting and setting cell values, removing rows, merging cells, and more. Image: Loading images from files or streams, setting wrap text, position offset, width, height, and other properties. Shape: Setting wrap text, position offset, width, height, shape type, and rotation. Word Document C# Library for .NET Download the C# library for handling DOCX documents Create and modify Word and DOCX documents Add document structures such as paragraphs, sections, and tables Add document elements such as text runs, images, and shapes Style the document elements with ease Installation IronWord Library Installing IronWord is quick and easy. You can install the package using NuGet with the following command: Install-Package IronWord Alternatively, download directly from the official IronWord NuGet website. Once installed, you can get started by adding using IronWord; to the top of your C# code file. Applying License Key Next, apply a valid license or trial key to IronWord by assigning the license key to the LicenseKey property of the License class. Include the following code right after the import statement, before using any IronWord methods: using IronWord; // Assign your license key License.LicenseKey = "YOUR_LICENSE_KEY_HERE"; using IronWord; // Assign your license key License.LicenseKey = "YOUR_LICENSE_KEY_HERE"; Imports IronWord ' Assign your license key License.LicenseKey = "YOUR_LICENSE_KEY_HERE" $vbLabelText $csharpLabel Code Examples Let’s explore some code examples and the features available. 请注意The DOCX file produced by IronWord, when opened in a certain version of Microsoft Word, may be in Compatibility Mode, causing some of the styling to be unavailable. To convert a Word document out of compatibility mode Select 'File' > 'Info' and click "Convert." You will be prompted with a message saying that your document will be upgraded to the newest file format. Click "OK." Create Word and Docx Document Create the Word document by instantiating the WordDocument class using one of its constructors. After that, use the SaveAs method to export the Word document. Example: using IronWord; class Program { static void Main() { // Create a new Word document var document = new WordDocument(); // Save the document as a .docx file document.SaveAs("example.docx"); } } using IronWord; class Program { static void Main() { // Create a new Word document var document = new WordDocument(); // Save the document as a .docx file document.SaveAs("example.docx"); } } Imports IronWord Friend Class Program Shared Sub Main() ' Create a new Word document Dim document = New WordDocument() ' Save the document as a .docx file document.SaveAs("example.docx") End Sub End Class $vbLabelText $csharpLabel Add Image An image cannot be added by itself; instead, it should be added to one of the document structures, such as a Paragraph, TableCell, or Section. Use the AddImage method to add an image. Example: using IronWord; using System.Drawing; class Program { static void Main() { var document = new WordDocument(); var section = document.Sections.Add(); // Add an image to a paragraph var paragraph = section.Paragraphs.Add(); paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100)); document.SaveAs("example_with_image.docx"); } } using IronWord; using System.Drawing; class Program { static void Main() { var document = new WordDocument(); var section = document.Sections.Add(); // Add an image to a paragraph var paragraph = section.Paragraphs.Add(); paragraph.AddImage("path/to/image.jpg", new Rectangle(0, 0, 100, 100)); document.SaveAs("example_with_image.docx"); } } Imports IronWord Imports System.Drawing Friend Class Program Shared Sub Main() Dim document = New WordDocument() Dim section = document.Sections.Add() ' Add an image to a paragraph Dim paragraph = section.Paragraphs.Add() paragraph.AddImage("path/to/image.jpg", New Rectangle(0, 0, 100, 100)) document.SaveAs("example_with_image.docx") End Sub End Class $vbLabelText $csharpLabel Add Table Adding a table requires creating the table, rows, columns, and table cells. This enables significant configuration opportunities, as each cell can have different styles. Example: using IronWord; class Program { static void Main() { var document = new WordDocument(); var section = document.Sections.Add(); var table = section.Tables.Add(3, 3); // 3x3 table // Iterate over cells and set their content for (int i = 0; i < table.Rows.Count; i++) { for (int j = 0; j < table.Rows[i].Cells.Count; j++) { table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}"); } } document.SaveAs("example_with_table.docx"); } } using IronWord; class Program { static void Main() { var document = new WordDocument(); var section = document.Sections.Add(); var table = section.Tables.Add(3, 3); // 3x3 table // Iterate over cells and set their content for (int i = 0; i < table.Rows.Count; i++) { for (int j = 0; j < table.Rows[i].Cells.Count; j++) { table.Rows[i].Cells[j].Paragraphs.Add().AppendText($"Cell {i+1},{j+1}"); } } document.SaveAs("example_with_table.docx"); } } Imports IronWord Friend Class Program Shared Sub Main() Dim document = New WordDocument() Dim section = document.Sections.Add() Dim table = section.Tables.Add(3, 3) ' 3x3 table ' Iterate over cells and set their content For i As Integer = 0 To table.Rows.Count - 1 Dim j As Integer = 0 Do While j < table.Rows(i).Cells.Count table.Rows(i).Cells(j).Paragraphs.Add().AppendText($"Cell {i+1},{j+1}") j += 1 Loop Next i document.SaveAs("example_with_table.docx") End Sub End Class $vbLabelText $csharpLabel Licensing & Support Available IronWord is a paid library; however, free trial licenses are available here. For more information about Iron Software, please visit our website: https://ironsoftware.com/. For more support and inquiries, please ask our team. Support from Iron Software For general support and technical inquiries, please email us at: support@ironsoftware.com Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Nuget 下载 25,807 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:25,807 查看许可证