IronWord 開始使用 Getting Started with IronWord Curtis Chau 更新日期:6月 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 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 25,807 | 版本: 2025.11 剛剛發布 免費 NuGet 下載 總下載量:25,807 查看許可證