在生產環境中測試,無水印。
在任何需要的地方都能運行。
獲得 30 天的全功能產品。
在幾分鐘內上手運行。
試用產品期間完全訪問我們的支援工程團隊
.NET Word API 為開發人員提供強大的工具,可在應用程式中轉換、互動及操作 MS Word 文件。 此 API 專為簡化處理 Microsoft Word 文件的過程而設計,使得程式化地創建、編輯、轉換和管理文件變得更加容易。 在本文中,我們將探索IronWord,以了解其在操作Word文檔方面的功能。
IronWord 是 .NET Word API 生態系統中的一個 .NET Word 庫,專為在其 .NET 應用程式中處理 Microsoft Word 文件的開發人員設計。 使用 IronWord,開發者可以輕鬆地讀取、撰寫和修改 Word 文件,而無需在伺服器或客戶端機器上安裝 Microsoft Word。 此功能對於需要自動化文檔處理任務的應用程式特別有利,例如通過郵件合併功能生成報告、發票或個性化信函。
IronWord 提供廣泛的功能,涵蓋 Word 文件處理的各個方面。 讓我們探索每組功能,重點是它們如何啟用多個文件的操作和合併,並根據「文件結構」和「文件元素」進行分類。
讀取和編輯 Word:使用 IronWord,您可以從 Word 文件中提取特定信息,例如提取文本進行編輯或重新利用,以及檢索需要在其他地方使用的圖片。 此功能對於旨在合併 Word 文檔和處理現有 DOCX 文件中信息的應用程式至關重要。
多種格式:IronWord 支援廣泛的文件格式,提升其在 .NET 應用程式中轉換 Word 文件的實用性。
編輯頁面設定:使用 IronWord,調整 Word 文件的實體版面配置變得輕而易舉。 您可以調整各種 MS Word 文件的紙張大小為標準或自訂尺寸,變更文檔不同部分的方向,設置邊距以確保正確對齊,甚至可以修改背景顏色以達到美觀效果或突顯某些部分。
新增段落:IronWord 支援新增和移除段落中的文本,這對於編輯和格式化大量文字內容非常重要。 此外,您可以通過將圖像和形狀直接插入到文本中來增強段落,調整樣式以符合您的設計規範,並設置對齊方式以達到精緻的外觀。 添加項目符號和編號列表的功能也有助於更有效地組織內容。
using IronWord;
using IronWord.Models;
// Load docx
WordDocument doc = new WordDocument();
// Create and add styled text to a paragraph
Paragraph paragraph = new Paragraph();
paragraph.AddTextRun(new TextRun("Exploring text styles within a document."));
paragraph.AddTextRun(new TextRun("An example in italic.", new TextStyle { IsItalic = true }));
paragraph.AddTextRun(new TextRun("An example in bold.", new TextStyle { IsBold = true }));
// Add paragraph and export docx
doc.AddParagraph(paragraph);
doc.SaveAs("newdocument.docx");
using IronWord;
using IronWord.Models;
// Load docx
WordDocument doc = new WordDocument();
// Create and add styled text to a paragraph
Paragraph paragraph = new Paragraph();
paragraph.AddTextRun(new TextRun("Exploring text styles within a document."));
paragraph.AddTextRun(new TextRun("An example in italic.", new TextStyle { IsItalic = true }));
paragraph.AddTextRun(new TextRun("An example in bold.", new TextStyle { IsBold = true }));
// Add paragraph and export docx
doc.AddParagraph(paragraph);
doc.SaveAs("newdocument.docx");
Imports IronWord
Imports IronWord.Models
' Load docx
Private doc As New WordDocument()
' Create and add styled text to a paragraph
Private paragraph As New Paragraph()
paragraph.AddTextRun(New TextRun("Exploring text styles within a document."))
paragraph.AddTextRun(New TextRun("An example in italic.", New TextStyle With {.IsItalic = True}))
paragraph.AddTextRun(New TextRun("An example in bold.", New TextStyle With {.IsBold = True}))
' Add paragraph and export docx
doc.AddParagraph(paragraph)
doc.SaveAs("newdocument.docx")
添加表格:表格是DOCX文件的重要組成部分,可以使用IronWord輕鬆操作,支持動態文件生成。 您可以新增或刪除列和欄,這是一個關鍵操作,用於動態文件生成,其中數據量可能會有所變化。 合併和拆分儲存格讓您能夠靈活地格式化複雜的表格,並且自訂邊框和佈局尺寸可提供精緻、專業的外觀。
using IronWord;
using IronWord.Models;
// Create a table cell with a paragraph containing text
TableCell cell = new TableCell(new Paragraph(new TextRun("Sample text")));
// Configure a common border style for the table
BorderStyle borderStyle = new BorderStyle
{
BorderColor = new IronColor(IronSoftware.Drawing.Color.Black),
BorderValue = IronWord.Models.Enums.BorderValues.Thick,
BorderSize = 5
};
// Apply the border style to the cell
cell.Borders = new TableBorders
{
TopBorder = borderStyle,
RightBorder = borderStyle,
BottomBorder = borderStyle,
LeftBorder = borderStyle
};
// Create a table row and add the same cell twice
TableRow row = new TableRow();
row.AddCell(cell);
row.AddCell(cell);
// Create a table, add the row, then create and export the Word document
Table table = new Table();
table.AddRow(row);
WordDocument doc = new WordDocument(table);
doc.SaveAs("Document.docx");
using IronWord;
using IronWord.Models;
// Create a table cell with a paragraph containing text
TableCell cell = new TableCell(new Paragraph(new TextRun("Sample text")));
// Configure a common border style for the table
BorderStyle borderStyle = new BorderStyle
{
BorderColor = new IronColor(IronSoftware.Drawing.Color.Black),
BorderValue = IronWord.Models.Enums.BorderValues.Thick,
BorderSize = 5
};
// Apply the border style to the cell
cell.Borders = new TableBorders
{
TopBorder = borderStyle,
RightBorder = borderStyle,
BottomBorder = borderStyle,
LeftBorder = borderStyle
};
// Create a table row and add the same cell twice
TableRow row = new TableRow();
row.AddCell(cell);
row.AddCell(cell);
// Create a table, add the row, then create and export the Word document
Table table = new Table();
table.AddRow(row);
WordDocument doc = new WordDocument(table);
doc.SaveAs("Document.docx");
Imports IronWord
Imports IronWord.Models
' Create a table cell with a paragraph containing text
Private cell As New TableCell(New Paragraph(New TextRun("Sample text")))
' Configure a common border style for the table
Private borderStyle As New BorderStyle With {
.BorderColor = New IronColor(IronSoftware.Drawing.Color.Black),
.BorderValue = IronWord.Models.Enums.BorderValues.Thick,
.BorderSize = 5
}
' Apply the border style to the cell
cell.Borders = New TableBorders With {
.TopBorder = borderStyle,
.RightBorder = borderStyle,
.BottomBorder = borderStyle,
.LeftBorder = borderStyle
}
' Create a table row and add the same cell twice
Dim row As New TableRow()
row.AddCell(cell)
row.AddCell(cell)
' Create a table, add the row, then create and export the Word document
Dim table As New Table()
table.AddRow(row)
Dim doc As New WordDocument(table)
doc.SaveAs("Document.docx")
新增文字運行:此功能專注於對文字內容的精細控制。 您可以添加、附加和分割文字運行,這對於動態文件的創建至關重要。 樣式選項非常廣泛,包括更改字體系列、大小和顏色,以及添加粗體、斜體和其他文字裝飾。 您也可以在文本中嵌入圖像,創建一個豐富且具有視覺吸引力的文檔。
新增圖片:IronWord 支援在 Word 文件中進行全面的圖片操作。 您可以從各種來源載入圖像,無縫地將文字環繞在圖像周圍,並調整其尺寸以適應您的版面配置。 能夠設置位置偏移和與文件角落的距離,這意味著您的圖像將始終完美地放置。
using IronWord;
using IronWord.Models;
WordDocument doc = new WordDocument();
IronWord.Models.Image image = new IronWord.Models.Image("your-image.jpg")
{
Width = 200, // In unit pixel
Height = 200 // In unit pixel
};
Create paragraph, add image, add paragraph to doc, and export
Paragraph paragraph = new Paragraph();
paragraph.AddImage(image);
doc.AddParagraph(paragraph);
doc.SaveAs("save_document.docx");
using IronWord;
using IronWord.Models;
WordDocument doc = new WordDocument();
IronWord.Models.Image image = new IronWord.Models.Image("your-image.jpg")
{
Width = 200, // In unit pixel
Height = 200 // In unit pixel
};
Create paragraph, add image, add paragraph to doc, and export
Paragraph paragraph = new Paragraph();
paragraph.AddImage(image);
doc.AddParagraph(paragraph);
doc.SaveAs("save_document.docx");
Imports IronWord
Imports IronWord.Models
Private doc As New WordDocument()
Private image As New IronWord.Models.Image("your-image.jpg") With {
.Width = 200,
.Height = 200
}
Private paragraph, add, add, [and] As Create
paragraph.AddImage(image)
doc.AddParagraph(paragraph)
doc.SaveAs("save_document.docx")
添加形狀:形狀可以對文件產生顯著的視覺影響,IronWord 提供了精確插入和自定義形狀的工具。 您可以設定形狀類型(如矩形、圓形、箭頭等)、決定文本如何環繞形狀、指定精確的尺寸和位置,甚至旋轉形狀以達到所需的視覺效果。
IronWord 專為 .NET 生態系統中的廣泛相容性而設計,支援 C#、VB.NET 和 F#,適用於各種 .NET 版本,包括 .NET Core、.NET Standard 和 .NET Framework。 這可確保其在當代和傳統應用中的實用性。 該程式庫的多功能性延伸至各類專案類型,通過與Blazor、WebForms、Xamarin、MAUI、WPF和控制台應用程式的整合,適用於網頁、移動和桌面應用程式。
在應用環境方面,IronWord 可適應 Windows、Linux、iOS 和 Android 平台,包括對 Docker、Azure 和 AWS 上的容器化和雲部署的具體支援。 這種廣泛的支援促進了在不同環境中的開發。
IronWord 也兼容主要的集成開發環境(IDE),例如 Microsoft Visual Studio、ReSharper 和 Rider,為開發人員在工具選擇上提供了靈活性。 最後,它支持各種作業系統和處理器架構(x64、x86、ARM),確保在不同的硬體配置中提供高效能表現。
IronWord 提供多種授權選項,以滿足不同開發者和組織的需求。 他們提供永久許可證,這意味著您只需一次性付款,且無需支付定期費用。 每個許可證都包含一年的產品支援及更新。 許可級別是根據您的開發人員數量、地點和項目數量設計的。 您也可以獲取免費試用,以便在購買許可證之前親自體驗。
此選項專為單獨開發專案的個人開發者量身打造。 它的價格為$749,並涵蓋單一地點的一位開發者。
針對小型團隊,此許可證售價為 $1,499,最多可供三名開發人員使用,適用於三個地點和三個專案。
對於較大的團隊,Professional License 的價格為 $2,999,支持最多十名開發人員。 它專為更大規模的操作而設計,並包括高級支援功能。
總結來說, IronWord 作為一個強大且靈活的 .NET Word API,提供多種授權選項以滿足個別開發者和團隊的多樣需求。 其功能可有效管理和操作 Word 文件,確保在多個 .NET 版本和項目類型之間的相容性。