產品比較 IronWord 與 Microsoft.Office.Interop.Word 之間的比較 Jordi Bardia 更新日期:8月 4, 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 1. Introduction Many developers work with .NET applications where they need to handle Word documents. This could be for creating reports, processing documents, or generating invoices. Two popular tools for this are Microsoft.Office.Interop.Word and IronWord. Each has its own set of features, pros, and cons. This article will compare Microsoft.Office.Interop.Word and IronWord. We will look at what each tool offers, how they perform, and in which scenarios they are best used. This should help you decide which tool is better for your specific needs. 2. Microsoft.Office.Interop.Word Microsoft.Office.Interop.Word is a library that enables .NET applications to interact directly with Microsoft Word documents. It's a key component for developers who need to automate Word document processes or integrate Word document manipulation capabilities into their .NET applications. This library is particularly useful for tasks such as document generation, modification, and formatting within the .NET environment, leveraging the full capabilities of Microsoft Word. 2.1 Key Features Document Creation and Editing: Microsoft.Office.Interop.Word provides extensive support for creating and editing Word documents. It allows developers to programmatically add, modify, and delete text, as well as manage document properties such as titles and subjects. This feature is essential for generating dynamic documents based on user input or external data sources. Formatting and Styles: The library offers comprehensive options for formatting text, paragraphs, and entire documents. Developers can apply various styles, fonts, colors, and paragraph alignments to create professionally formatted documents. This includes the ability to define and apply custom styles over the default, ensuring that generated documents meet specific branding or design requirements. Compatibility with Microsoft Word: As a component of the Microsoft Office suite, Microsoft.Office.Interop.Word ensures high fidelity and compatibility with all features of Microsoft Word. This includes seamless integration with the latest versions of Word, ensuring that documents created or modified through the library are fully compatible with Word's native format. 3. IronWord IronWord is a .NET library designed for document manipulation, specifically targeting Word document processing. Unlike Microsoft.Office.Interop.Word, which relies on the Microsoft Office suite, IronWord provides a standalone solution for creating, editing, and converting Word documents within .NET applications. This makes it an attractive option for developers looking for a library that doesn't require Microsoft Word to be installed on the server or client machines. 3.1 Key Features Standalone Document Processing: IronWord enables the manipulation of Word documents directly within .NET applications without the need for Microsoft Office Word to be installed. This independence simplifies deployment and reduces the complexity of development environments, especially in server or cloud contexts. Document Conversion: A significant capability of IronWord is its support for converting Word documents to other formats, such as PDF, HTML, and plain text. This feature is essential for applications that need to present documents in multiple formats or for web applications that require document content to be displayed in HTML. Comprehensive Formatting Options: IronWord offers a wide range of formatting capabilities, allowing developers to apply text styles, add paragraph alignments, and insert elements like tables and images. These options ensure that documents generated or modified by IronWord meet the required visual and structural standards. Easy Integration with .NET Projects: Designed with .NET applications in mind, IronWord can be easily integrated into any .NET project through NuGet. Its API is designed to be intuitive for .NET developers, making it straightforward to start working with Word documents. Cross-Platform Compatibility: IronWord supports cross-platform development, making it suitable for use in applications targeting various operating systems. This is particularly valuable for projects that need to run on both the Windows operating system and the Linux operating system, or in cloud environments. 4. Creating the .NET Project in Visual Studio 4.1 Open in Visual Studio Start by launching Microsoft Visual Studio. Upon opening the application, you will be greeted by the start window. This window offers various options to get started, including opening an existing project or creating a new one. For our purpose, you'll focus on initiating a new project. 4.2 Choosing the Project Type After clicking on the option to create a new project, Visual Studio presents you with a list of templates. To proceed, select the Console App project. 4.3 Configuring the Project Once you've selected the desired project template, clicking 'Next' takes you to the project configuration screen. Here, you're required to provide essential details about your project. This includes specifying the project name and selecting the location where your project files will be stored, like a program files folder, reserved for internal use by applications. The next dialog box involves selecting the target framework. The .NET Framework you choose determines the libraries and APIs available to your application, influencing its compatibility and functionality. Make sure to select a framework version that supports the features you plan to implement in your application, leveraging Visual Studio tools for an optimized development experience. 4.4 Creating the Project After filling out the necessary information and ensuring all settings are correctly adjusted to meet your project's requirements, the final step is to create the project. This is achieved by clicking the 'Create' button. Visual Studio then initializes a new project based on the selected template and configurations. This process may take a few moments, after which your new .NET project will be open and ready for development. 5. Install IronWord Library This section delves into how you can incorporate the IronWord library into your project using the NuGet Package Manager, the Visual Studio Command Line, and directly download it from the NuGet webpage. 5.1 Using the NuGet Package Manager The NuGet Package Manager is a user-friendly interface within Visual Studio that allows for the seamless installation of libraries and tools. To install the IronWord library using this method, follow these steps: Open the NuGet Package Manager: With your project open, right-click on the project name in the Solution Explorer and select "Manage NuGet Packages..." from the context menu. This action opens the NuGet Package Manager window. Search for IronWord: In the NuGet Package Manager window, navigate to the "Browse" tab. Use the search box to find the IronWord library by entering "IronWord" and pressing Enter. Install IronWord: From the search results, select the IronWord package. You will see a detailed description and version information. Choose the version that suits your project requirements and click the "Install" button. Visual Studio then handles the download and installation of the library, updating your project references accordingly. 5.2 Using the Visual Studio Command Line For those who prefer working with command-line tools, Visual Studio offers the Package Manager Console, a PowerShell interface for managing NuGet packages. Access the Package Manager Console: Navigate to "Tools" > "NuGet Package Manager" > "Package Manager Console" from the main menu in Visual Studio. Install IronWord: In the console, type the following command and press Enter: Install-Package IronWord This command fetches the latest version of the IronWord library and incorporates it into your project. You can specify a particular version by adding the -Version parameter followed by the version number. 5.3 Direct Download from the NuGet Webpage If you prefer to manually manage your project's libraries, you can directly download the IronWord package from the NuGet website and add it to your project. Download the Package: Visit nuget.org and search for the IronWord package. On the package page, find the "Download" link to get the .nupkg file. Save this file to your computer. Add to Project: Once downloaded, you can add the package to your project manually. This process typically involves extracting the .nupkg file and then adding references to the contained assemblies in your project. However, it's generally more straightforward and less error-prone to use the NuGet Package Manager or the Visual Studio Command Line as described above. 6. Install Microsoft.Office.Interop.Word This library can be added to your project through various approaches, each suited to different development preferences and requirements. 6.1 Using the NuGet Package Manager The NuGet Package Manager in Visual Studio is the most straightforward method to add the Microsoft.Office.Interop.Word library to your project. Follow these steps: Open NuGet Package Manager: With your project open in Visual Studio, right-click on the project name in the Solution Explorer. Select "Manage NuGet Packages..." from the context menu to open the NuGet Package Manager window. Search for the Library: In the NuGet Package Manager window, switch to the "Browse" tab and type "Microsoft.Office.Interop.Word" in the search box. Press Enter to initiate the search. Install the Package: Find the "Microsoft.Office.Interop.Word" package in the search results. Review the provided version information and description to ensure it meets your project's needs. Click on the "Install" button to add the library to your project. Visual Studio will handle the package download and installation, updating your project references to include the necessary assembly. 6.2 Using the Visual Studio Command Line The Package Manager Console, a command-line interface within Visual Studio, offers another way to install the Microsoft.Office.Interop.Word library. Access the Package Manager Console: Go to "Tools" > "NuGet Package Manager" > "Package Manager Console" from the main menu in Visual Studio. Execute the Installation Command: In the console, type the following command and press Enter: Install-Package Microsoft.Office.Interop.Word This command instructs Visual Studio to fetch the latest version of the library and integrate it into your project. If you need a specific version of the library, you can specify it by appending the -Version parameter followed by the desired version number. 6.3 Direct Download from the NuGet Webpage For developers who prefer manual management of project dependencies, the Microsoft.Office.Interop.Word library can be directly downloaded from the NuGet website. Download the Package: Navigate to nuget.org and search for "Microsoft.Office.Interop.Word". On the package's page, find the "Download" link to obtain the .nupkg file. Save this file to a known location on your computer. Manually Add the Package to Your Project: After downloading, the .nupkg file can be manually added to your project. This typically involves extracting the file and adding references to the extracted assemblies in your project. Nonetheless, for ease of use and to minimize potential errors, utilizing the NuGet Package Manager or the Visual Studio Command Line is recommended. 7. Comparison of Advanced Features in IronWord and Microsoft.Office.Interop.Word 7.1 IronWord's Advanced Features 7.1.1 Read & Edit Word Documents IronWord allows for the reading and modification of Word documents. This includes opening existing documents, making changes, and saving those changes back to the original document or a new file. This feature is essential for applications that need to update documents based on user input or data from other sources. using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument document = new WordDocument("my_new_document.docx"); // Insert new text content into the document document.AddText("This is a demonstration of modifying content with IronWord."); // Save the document with a new filename document.SaveAs("updated_document.docx"); using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument document = new WordDocument("my_new_document.docx"); // Insert new text content into the document document.AddText("This is a demonstration of modifying content with IronWord."); // Save the document with a new filename document.SaveAs("updated_document.docx"); Imports IronWord Imports IronWord.Models ' Initialize a new Word document Private document As New WordDocument("my_new_document.docx") ' Insert new text content into the document document.AddText("This is a demonstration of modifying content with IronWord.") ' Save the document with a new filename document.SaveAs("updated_document.docx") $vbLabelText $csharpLabel 7.1.2 Edit Page Setup IronWord enables changing the paper size of a document, accommodating various standards like A4, Letter, or Legal. You can adjust the page orientation between portrait and landscape, depending on the document's requirements. 7.1.3 Add Paragraphs Adding paragraphs programmatically is straightforward with IronWord, making it possible to insert text dynamically based on application logic. using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument document = new WordDocument(); // Insert text into the document document.AddText("Exploring IronWord Capabilities"); // Save the document to a new file document.SaveAs("updated_ironword_document.docx"); using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument document = new WordDocument(); // Insert text into the document document.AddText("Exploring IronWord Capabilities"); // Save the document to a new file document.SaveAs("updated_ironword_document.docx"); Imports IronWord Imports IronWord.Models ' Initialize a new Word document Private document As New WordDocument() ' Insert text into the document document.AddText("Exploring IronWord Capabilities") ' Save the document to a new file document.SaveAs("updated_ironword_document.docx") $vbLabelText $csharpLabel 7.1.4 Add & Remove TextRuns TextRuns represent sections of text with a common set of properties. IronWord allows for adding and removing these, giving developers control over text segmentation and properties. 7.1.5 Add Images IronWord supports adding images to documents, including specifying their position, wrapping, and size, which enhances the visual appeal and effectiveness of the document. using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument document = new WordDocument(); // Setup an image IronWord.Models.Image img = new IronWord.Models.Image("updated_image.jpg"); img.Width = 250; // Width in pixels img.Height = 250; // Height in pixels // Create a paragraph to contain the image Paragraph para = new Paragraph(); // Incorporate an image into the paragraph para.AddImage(img); // Add the paragraph to the document document.AddParagraph(para); // Save the document with a new name document.SaveAs("updated_save_document.docx"); using IronWord; using IronWord.Models; // Initialize a new Word document WordDocument document = new WordDocument(); // Setup an image IronWord.Models.Image img = new IronWord.Models.Image("updated_image.jpg"); img.Width = 250; // Width in pixels img.Height = 250; // Height in pixels // Create a paragraph to contain the image Paragraph para = new Paragraph(); // Incorporate an image into the paragraph para.AddImage(img); // Add the paragraph to the document document.AddParagraph(para); // Save the document with a new name document.SaveAs("updated_save_document.docx"); Imports IronWord Imports IronWord.Models ' Initialize a new Word document Private document As New WordDocument() ' Setup an image Private img As New IronWord.Models.Image("updated_image.jpg") img.Width = 250 ' Width in pixels img.Height = 250 ' Height in pixels ' Create a paragraph to contain the image Dim para As New Paragraph() ' Incorporate an image into the paragraph para.AddImage(img) ' Add the paragraph to the document document.AddParagraph(para) ' Save the document with a new name document.SaveAs("updated_save_document.docx") $vbLabelText $csharpLabel 7.1.6 Add Shapes Shapes can be added to documents with IronWord, including setting the shape type, size, position, and rotation. This adds a layer of visual interest and can be used to highlight information or add decorative elements. 7.1.7 Set Styling Styling options in IronWord are extensive, covering font family and size, color, and text decorations like bold, italic, strikethrough, underline, superscript, and subscript. This level of control is crucial for maintaining brand standards and ensuring document readability. using IronSoftware.Drawing; using IronWord; using IronWord.Models; using Color = IronSoftware.Drawing.Color; // Initialize WordDocument with a file WordDocument document = new WordDocument("updated_document.docx"); // Create a TextRun with modifications TextRun modifiedTextRun = new TextRun { Text = "Updated text with IronWord", Style = new TextStyle { FontFamily = "Arial", FontSize = 48, // Adjusted font size TextColor = new IronColor(Color.Blue), IsBold = false, IsItalic = false, IsUnderline = false, IsSuperscript = true, IsStrikethrough = false, IsSubscript = true } }; // Create a paragraph and add the TextRun Paragraph newParagraph = new Paragraph(); newParagraph.AddTextRun(modifiedTextRun); // Add the paragraph to the document document.AddParagraph(newParagraph); // Save the document with a new name document.SaveAs("updated_save_document.docx"); using IronSoftware.Drawing; using IronWord; using IronWord.Models; using Color = IronSoftware.Drawing.Color; // Initialize WordDocument with a file WordDocument document = new WordDocument("updated_document.docx"); // Create a TextRun with modifications TextRun modifiedTextRun = new TextRun { Text = "Updated text with IronWord", Style = new TextStyle { FontFamily = "Arial", FontSize = 48, // Adjusted font size TextColor = new IronColor(Color.Blue), IsBold = false, IsItalic = false, IsUnderline = false, IsSuperscript = true, IsStrikethrough = false, IsSubscript = true } }; // Create a paragraph and add the TextRun Paragraph newParagraph = new Paragraph(); newParagraph.AddTextRun(modifiedTextRun); // Add the paragraph to the document document.AddParagraph(newParagraph); // Save the document with a new name document.SaveAs("updated_save_document.docx"); Imports IronSoftware.Drawing Imports IronWord Imports IronWord.Models Imports Color = IronSoftware.Drawing.Color ' Initialize WordDocument with a file Private document As New WordDocument("updated_document.docx") ' Create a TextRun with modifications Private modifiedTextRun As New TextRun With { .Text = "Updated text with IronWord", .Style = New TextStyle With { .FontFamily = "Arial", .FontSize = 48, .TextColor = New IronColor(Color.Blue), .IsBold = False, .IsItalic = False, .IsUnderline = False, .IsSuperscript = True, .IsStrikethrough = False, .IsSubscript = True } } ' Create a paragraph and add the TextRun Private newParagraph As New Paragraph() newParagraph.AddTextRun(modifiedTextRun) ' Add the paragraph to the document document.AddParagraph(newParagraph) ' Save the document with a new name document.SaveAs("updated_save_document.docx") $vbLabelText $csharpLabel 7.1.8 Set Alignments IronWord supports setting text alignment within the document, including left, center, right, and justified alignments. This is important for both aesthetics and readability. 7.1.10 Add Tables Tables are a vital component of many documents, used for organizing data and information. IronWord allows for adding tables and manipulating their structure, including adding or removing rows and columns. Manipulating the content of table cells is straightforward with IronWord, enabling dynamic content insertion based on application needs. IronWord provides the ability to merge and split table cells, which is useful for customizing table layouts and addressing complex data presentation requirements. using IronWord; using IronWord.Models; // Create a table cell TableCell cell = new TableCell(); TextRun textRun = new TextRun(); textRun.Text = "Updated content"; // Changed the text content // Add a TextRun to the cell cell.AddContent(new Paragraph(textRun)); // Configure border style BorderStyle borderStyle = new BorderStyle { BorderColor = new IronColor(IronSoftware.Drawing.Color.Blue), // Changed border color to blue BorderValue = IronWord.Models.Enums.BorderValues.Double, // Changed border style to double BorderSize = 3 // Adjusted border size to 3 }; // Configure table border TableBorders tableBorders = new TableBorders { TopBorder = borderStyle, RightBorder = borderStyle, BottomBorder = borderStyle, LeftBorder = borderStyle, }; // Assign borders to the cell cell.Borders = tableBorders; // Create a row and add the cell TableRow row = new TableRow(); row.AddCell(cell); row.AddCell(cell); // Create a table and add the row Table table = new Table(); table.AddRow(row); // Create a new Word document from the table WordDocument doc = new WordDocument(table); // Export the Word document doc.SaveAs("UpdatedDocument.docx"); using IronWord; using IronWord.Models; // Create a table cell TableCell cell = new TableCell(); TextRun textRun = new TextRun(); textRun.Text = "Updated content"; // Changed the text content // Add a TextRun to the cell cell.AddContent(new Paragraph(textRun)); // Configure border style BorderStyle borderStyle = new BorderStyle { BorderColor = new IronColor(IronSoftware.Drawing.Color.Blue), // Changed border color to blue BorderValue = IronWord.Models.Enums.BorderValues.Double, // Changed border style to double BorderSize = 3 // Adjusted border size to 3 }; // Configure table border TableBorders tableBorders = new TableBorders { TopBorder = borderStyle, RightBorder = borderStyle, BottomBorder = borderStyle, LeftBorder = borderStyle, }; // Assign borders to the cell cell.Borders = tableBorders; // Create a row and add the cell TableRow row = new TableRow(); row.AddCell(cell); row.AddCell(cell); // Create a table and add the row Table table = new Table(); table.AddRow(row); // Create a new Word document from the table WordDocument doc = new WordDocument(table); // Export the Word document doc.SaveAs("UpdatedDocument.docx"); Imports IronWord Imports IronWord.Models ' Create a table cell Private cell As New TableCell() Private textRun As New TextRun() textRun.Text = "Updated content" ' Changed the text content ' Add a TextRun to the cell cell.AddContent(New Paragraph(textRun)) ' Configure border style Dim borderStyle As New BorderStyle With { .BorderColor = New IronColor(IronSoftware.Drawing.Color.Blue), .BorderValue = IronWord.Models.Enums.BorderValues.Double, .BorderSize = 3 } ' Configure table border Dim tableBorders As New TableBorders With { .TopBorder = borderStyle, .RightBorder = borderStyle, .BottomBorder = borderStyle, .LeftBorder = borderStyle } ' Assign borders to the cell cell.Borders = tableBorders ' Create a row and add the cell Dim row As New TableRow() row.AddCell(cell) row.AddCell(cell) ' Create a table and add the row Dim table As New Table() table.AddRow(row) ' Create a new Word document from the table Dim doc As New WordDocument(table) ' Export the Word document doc.SaveAs("UpdatedDocument.docx") $vbLabelText $csharpLabel 7.2 Microsoft.Office.Interop.Word's Specific Advanced Features Microsoft.Office.Interop.Word allows for deep integration with Word documents, enabling developers to leverage Word's extensive features programmatically. Below are specific advanced features offered by Microsoft.Office.Interop.Word, distinct from the general capabilities outlined earlier: 7.2.1 Content Controls Microsoft.Office.Interop.Word supports the addition and manipulation of content controls, which include rich text boxes, combo boxes, date pickers, and checkboxes. These controls can be used to create structured and interactive documents where users can input or select information within a set template. using Microsoft.Office.Interop.Word; // Create a new Word application and document var application = new Application(); var document = application.Documents.Add(); // Add a combo box content control object missing = System.Reflection.Missing.Value; var cc = document.ContentControls.Add(WdContentControlType.wdContentControlComboBox, ref missing); cc.Title = "Choose an option"; cc.DropdownListEntries.Add("Option 1", "1"); cc.DropdownListEntries.Add("Option 2", "2"); using Microsoft.Office.Interop.Word; // Create a new Word application and document var application = new Application(); var document = application.Documents.Add(); // Add a combo box content control object missing = System.Reflection.Missing.Value; var cc = document.ContentControls.Add(WdContentControlType.wdContentControlComboBox, ref missing); cc.Title = "Choose an option"; cc.DropdownListEntries.Add("Option 1", "1"); cc.DropdownListEntries.Add("Option 2", "2"); Imports Microsoft.Office.Interop.Word ' Create a new Word application and document Private application = New Application() Private document = application.Documents.Add() ' Add a combo box content control Private missing As Object = System.Reflection.Missing.Value Private cc = document.ContentControls.Add(WdContentControlType.wdContentControlComboBox, missing) cc.Title = "Choose an option" cc.DropdownListEntries.Add("Option 1", "1") cc.DropdownListEntries.Add("Option 2", "2") $vbLabelText $csharpLabel 7.2.2 Mail Merge Automate the mail merge process, which combines a Word document with a data source like a spreadsheet or a database, to produce personalized letters, labels, or emails in bulk. This feature is invaluable for generating customized communications or documents en masse. using Microsoft.Office.Interop.Word; // Create a new document for mail merge var mailMergeDoc = application.Documents.Add(); // Open the data source for the mail merge mailMergeDoc.MailMerge.OpenDataSource("path\\to\\datasource.xlsx"); // Execute the mail merge mailMergeDoc.MailMerge.Destination = WdMailMergeDestination.wdSendToNewDocument; mailMergeDoc.MailMerge.Execute(false); using Microsoft.Office.Interop.Word; // Create a new document for mail merge var mailMergeDoc = application.Documents.Add(); // Open the data source for the mail merge mailMergeDoc.MailMerge.OpenDataSource("path\\to\\datasource.xlsx"); // Execute the mail merge mailMergeDoc.MailMerge.Destination = WdMailMergeDestination.wdSendToNewDocument; mailMergeDoc.MailMerge.Execute(false); Imports Microsoft.Office.Interop.Word ' Create a new document for mail merge Private mailMergeDoc = application.Documents.Add() ' Open the data source for the mail merge mailMergeDoc.MailMerge.OpenDataSource("path\to\datasource.xlsx") ' Execute the mail merge mailMergeDoc.MailMerge.Destination = WdMailMergeDestination.wdSendToNewDocument mailMergeDoc.MailMerge.Execute(False) $vbLabelText $csharpLabel 7.2.3 Track Changes and Comments Enable and interact with Word's track changes and comments features through code. This functionality is essential for applications that require collaborative editing, document review, or auditing changes over time. using Microsoft.Office.Interop.Word; // Enable track changes document.TrackRevisions = true; // Add a comment to the first paragraph object start = 0; object end = 0; Range range = document.Paragraphs[1].Range; document.Comments.Add(range, "This is a comment."); using Microsoft.Office.Interop.Word; // Enable track changes document.TrackRevisions = true; // Add a comment to the first paragraph object start = 0; object end = 0; Range range = document.Paragraphs[1].Range; document.Comments.Add(range, "This is a comment."); Imports Microsoft.Office.Interop.Word ' Enable track changes document.TrackRevisions = True ' Add a comment to the first paragraph Dim start As Object = 0 Dim [end] As Object = 0 Dim range As Range = document.Paragraphs(1).Range document.Comments.Add(range, "This is a comment.") $vbLabelText $csharpLabel 7.2.4 Headers and Footers Manipulate headers and footers dynamically, including adding page numbers, dates, or custom text. This is vital for creating professional documents with consistent branding and navigation aids. using Microsoft.Office.Interop.Word; // Iterate through sections in the document and set headers and footers foreach (Section section in document.Sections) { // Set text for primary header section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "Header Text"; // Add page numbers to primary footer section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(); } using Microsoft.Office.Interop.Word; // Iterate through sections in the document and set headers and footers foreach (Section section in document.Sections) { // Set text for primary header section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "Header Text"; // Add page numbers to primary footer section.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(); } Imports Microsoft.Office.Interop.Word ' Iterate through sections in the document and set headers and footers For Each section As Section In document.Sections ' Set text for primary header section.Headers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Text = "Header Text" ' Add page numbers to primary footer section.Footers(WdHeaderFooterIndex.wdHeaderFooterPrimary).PageNumbers.Add() Next section $vbLabelText $csharpLabel 7.2.5 Table of Contents and Indexes Generate and update a table of contents or index based on document headings or marked entries. This is key for creating navigable, professional documents, especially lengthy reports or books. using Microsoft.Office.Interop.Word; // Add a table of contents to the document var toc = document.TablesOfContents.Add(document.Content, UpperHeadingLevel: 1, LowerHeadingLevel: 3, UseHyperlinks: true); // Add an index to the document var index = document.Indexes.Add(document.Content); using Microsoft.Office.Interop.Word; // Add a table of contents to the document var toc = document.TablesOfContents.Add(document.Content, UpperHeadingLevel: 1, LowerHeadingLevel: 3, UseHyperlinks: true); // Add an index to the document var index = document.Indexes.Add(document.Content); Imports Microsoft.Office.Interop.Word ' Add a table of contents to the document Private toc = document.TablesOfContents.Add(document.Content, UpperHeadingLevel:= 1, LowerHeadingLevel:= 3, UseHyperlinks:= True) ' Add an index to the document Private index = document.Indexes.Add(document.Content) $vbLabelText $csharpLabel 7.2.6 Embedding and Linking Objects Embed or link external objects like Excel charts or PowerPoint presentations into Word documents. This capability allows for dynamic content that updates with the source file or embedding information directly within the document. using Microsoft.Office.Interop.Word; // Embed an Excel sheet into the document object missing = System.Reflection.Missing.Value; document.InlineShapes.AddOLEObject( ClassType: "Excel.Sheet", FileName: "path\\to\\excel.xlsx", LinkToFile: false, DisplayAsIcon: false, IconFileName: ref missing, IconIndex: ref missing, IconLabel: ref missing, Anchor: ref missing ); using Microsoft.Office.Interop.Word; // Embed an Excel sheet into the document object missing = System.Reflection.Missing.Value; document.InlineShapes.AddOLEObject( ClassType: "Excel.Sheet", FileName: "path\\to\\excel.xlsx", LinkToFile: false, DisplayAsIcon: false, IconFileName: ref missing, IconIndex: ref missing, IconLabel: ref missing, Anchor: ref missing ); Imports Microsoft.Office.Interop.Word ' Embed an Excel sheet into the document Private missing As Object = System.Reflection.Missing.Value document.InlineShapes.AddOLEObject(ClassType:= "Excel.Sheet", FileName:= "path\to\excel.xlsx", LinkToFile:= False, DisplayAsIcon:= False, IconFileName:= missing, IconIndex:= missing, IconLabel:= missing, Anchor:= missing) $vbLabelText $csharpLabel 8. Documentation and Support 8.1 IronWord Documentation and Support IronWord offers thorough documentation and support to aid developers in harnessing its full potential. The documentation encompasses a wide array of resources, including a detailed getting started guide, feature summaries, quick-start examples, and comprehensive API references. Support for IronWord is robust, providing technical assistance to ensure developers can resolve any issues swiftly. The support framework includes a dedicated team available to address queries and troubleshoot problems. 8.2 Microsoft.Office.Interop.Word Documentation and Support Microsoft.Office.Interop.Word provides .NET developers with the tools to programmatically interact with Word documents, backed by Microsoft's extensive documentation and support. The documentation includes everything from beginner guides to advanced examples, detailed API information, and practical use cases. For support, Microsoft offers multiple channels, including direct technical assistance, community forums, and platforms like Stack Overflow for peer support. GitHub is also crucial for reporting issues and suggesting improvements. Regular updates ensure the library stays current with new Word versions, reflecting Microsoft's ongoing commitment to developer needs. 9. Licensing Models 9.1 IronWord License IronWord offers both free and commercial licensing options. Lite License: $liteLicense USD For 1 developer 1 location 1 project Email support Plus License: $plusLicense USD Up to 3 developers 3 locations 3 projects Email (24/7) and chat support Phone support Professional License: $professionalLicense USD Up to 10 developers 10 locations 10 projects Email (24/7), chat, and phone support Screen sharing support All commercial licenses include priority support and updates. It also offers a free trial to test out all capabilities in a production environment without any watermark. 9.2 Microsoft.Office.Interop.Word License The licensing for Microsoft.Office.Interop.Word is tied to the Microsoft Office suite. There's no separate license needed for the Interop library itself; it's included with Microsoft Office. The use of Microsoft.Office.Interop.Word in applications requires that the deployment environment has a valid Microsoft Office license, which includes Word. The cost is dependent on the specific Office suite version and licensing agreement chosen, ranging from individual licenses to volume licensing for businesses. For precise pricing, refer to Microsoft's official website or contact a Microsoft sales representative. 10. Conclusion In the comparison between IronWord and Microsoft.Office.Interop.Word, we've examined various aspects such as functionality, ease of use, platform compatibility, and licensing. IronWord emerges as a particularly strong contender for developers seeking a flexible, cross-platform solution for Word document manipulation. With its ability to operate independently of Microsoft Office, IronWord offers a streamlined approach to document processing, making it an ideal choice for applications running in diverse environments. Its comprehensive feature set, combined with the convenience of not requiring Microsoft Word to be installed, gives IronWord an edge, especially in scenarios where deployment simplicity and broad compatibility are key considerations. If you want to buy IronWord, go to the license page. 請注意Microsoft.Office.Interop.Word is a registered trademark of its respective owner. This site is not affiliated with, endorsed by, or sponsored by Microsoft.Office.Interop.Word. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing. 常見問題解答 如何在不安裝Microsoft Word的情況下在.NET中創建、編輯和格式化Word文檔? 您可以使用IronWord,這是一個獨立的.NET庫,允許文檔操作,轉換為各種格式,並提供全面的格式選項,而無需安裝Microsoft Word。 Microsoft.Office.Interop.Word和IronWord for .NET項目的區別是什麼? Microsoft.Office.Interop.Word需要安裝Microsoft Word並提供與Word功能的深度整合。IronWord是一個獨立的庫,無需Word,並支持跨平台開發,這使其在伺服器或雲環境中更具靈活性。 如何使用Visual Studio安裝.NET庫進行Word文檔處理? IronWord和Microsoft.Office.Interop.Word都可以通過Visual Studio中的NuGet包管理器、Visual Studio命令行或從NuGet網站直接下載進行安裝。 IronWord有哪些許可證選擇? IronWord提供多種許可證選擇,包括免費和商業許可證,分為Lite、Plus和Professional階層,每個具備不同的開發者、地點和項目限制。 Microsoft.Office.Interop.Word如何整合Microsoft Word功能? Microsoft.Office.Interop.Word允許.NET應用程式利用Word的完整功能,包括文檔創建、編輯、格式化、內容控制、郵件合併和其他高級功能,需要安裝Microsoft Word。 哪個庫更適合在.NET中進行跨平台開發? IronWord更適合跨平台開發,因為它不依賴於安裝Microsoft Word,並支持不同操作系統上的應用程式。 IronWord為文檔操作提供了哪些高級功能? IronWord提供高級功能,如閱讀和編輯Word文檔、設置頁面、添加段落、圖片、表格,並應用樣式和對齊方式,而無需Microsoft Word。 選擇IronWord和Microsoft.Office.Interop.Word時的關鍵考慮因素是什麼? 考慮您的環境中是否已安裝Microsoft Word以及是否需要與Word功能的深度整合。IronWord為伺服器或雲端應用提供了靈活性,而無需Word,而Microsoft.Office.Interop.Word則提供全面的Word功能訪問,但需要安裝Word。 Jordi Bardia 立即與工程團隊聊天 軟體工程師 Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。 相關文章 更新日期 7月 28, 2025 IronWord 與 Aspose Words For .NET 之間的比較 考慮將 Aspose.Word 作為您工具庫中的多功能工具,善於處理多種文件格式,並提供廣泛的功能以進行複雜的文件創建和操作 閱讀更多 IronWord 與 Aspose Words For .NET ...
更新日期 7月 28, 2025 IronWord 與 Aspose Words For .NET 之間的比較 考慮將 Aspose.Word 作為您工具庫中的多功能工具,善於處理多種文件格式,並提供廣泛的功能以進行複雜的文件創建和操作 閱讀更多