翻譯|使用教程|編輯:李顯亮|2019-05-30 11:39:18.457|閱讀 612 次
概述:Aspose.Words For .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words For .Net是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,API支持所有流行的Word處理文件格式,并允許將Word文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
【下載Aspose.Words for .NET最新試用版】
您可以使用Document.Styles屬性獲取文檔中定義的樣式集合。此集合包含文檔中的內置和用戶定義樣式。可以通過名稱/別名,樣式標識符或索引獲取特定樣式。 下面的代碼示例顯示了如何訪問文檔中定義的樣式集合。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); // Load the template document. Document doc = new Document(dataDir + "TestFile.doc"); // Get styles collection from document. StyleCollection styles = doc.Styles; string styleName = ""; // Iterate through all the styles. foreach (Style style in styles) { if (styleName == "") { styleName = style.Name; } else { styleName = styleName + ", " + style.Name; } }
您可以使用Document.Variables屬性獲取文檔變量的集合。變量名稱和值是字符串。下面的代碼示例顯示了如何枚舉文檔變量。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); // Load the template document. Document doc = new Document(dataDir + "TestFile.doc"); string variables = ""; foreach (KeyValuePairentry in doc.Variables) { string name = entry.Key.ToString(); string value = entry.Value.ToString(); if (variables == "") { // Do something useful. variables = "Name: " + name + "," + "Value: {1}" + value; } else { variables = variables + "Name: " + name + "," + "Value: {1}" + value; } }
下面我們一起來了解Aspose.Words如何支持Microsoft Word的Track Changes功能。 Microsoft Word中的“跟蹤更改”功能(也稱為“審閱”)允許您跟蹤用戶對內容和格式的更改。啟用此功能后,將直觀地突出顯示文檔的所有插入,刪除和修改元素,并提供有關更改者,時間和內容的信息。攜帶有關更改內容的信息的對象稱為“跟蹤更改”或“修訂”。
當您使用Aspose.Words打開Microsoft Word文檔然后保存它時,將保留文檔中的所有注釋和修訂。
該Document.AcceptAllRevisions方法讓你“接受”文檔中的所有修訂。調用此方法類似于在Microsoft Word中選擇“接受所有更改”。Aspose.Words實際上會刪除“刪除修訂版”的片段,保留“插入修訂版”的片段并應用格式更改。請注意,此操作期間注釋不受影響。在Aspose.Words中,您可以通過調用Document.AcceptAllRevisions方法接受對文檔的跟蹤更改。 下面的代碼示例顯示了如何接受文檔中的所有跟蹤更改。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); Document doc = new Document(dataDir + "Document.doc"); // Start tracking and make some revisions. doc.StartTrackRevisions("Author"); doc.FirstSection.Body.AppendParagraph("Hello world!"); // Revisions will now show up as normal text in the output document. doc.AcceptAllRevisions(); dataDir = dataDir + "Document.AcceptedRevisions_out.doc"; doc.Save(dataDir);
可以在Word文檔中插入,刪除和格式化更改修訂。Aspose.Words允許您以編程方式檢測某些類型的修訂.InsInsertRevision,IsDeleteRevision,IsMoveFromRevision和IsMoveToRevision屬性可用于Run和Paragraph對象,允許您在更改跟蹤時檢測此對象是否在Microsoft Word中插入,刪除或移動如果文檔至少有一個版本,則Document.HasRevisions屬性返回true。可以將Document.TrackRevisions屬性設置為true,以指示是否啟用Microsoft Word中的修訂跟蹤。
Document doc = new Document(dataDir + "Revisions.docx"); ParagraphCollection paragraphs = doc.FirstSection.Body.Paragraphs; for (int i = 0; i < paragraphs.Count; i++) { if (paragraphs[i].IsMoveFromRevision) Console.WriteLine("The paragraph {0} has been moved (deleted).", i); if (paragraphs[i].IsMoveToRevision) Console.WriteLine("The paragraph {0} has been moved (inserted).", i); }
Aspose.Words中的修訂是一個文檔節點的更改。相鄰文檔節點中的相同類型的一組順序修訂形成修訂組。類似的修訂組顯示在MS Word的“審閱窗格”中。RevisionGroup類表示一組順序的Revision對象。 下面的代碼示例顯示了如何獲取修訂版及其組。
Document doc = new Document(dataDir + "Revisions.docx"); foreach (RevisionGroup group in doc.Revisions.Groups) { Console.WriteLine("{0}, {1}:", group.Author, group.RevisionType); Console.WriteLine(group.Text); }
你可以通過獲取Document.ProtectionType屬性的值來檢索文檔保護的類型。下面的代碼示例顯示了如何獲取當前在文檔中設置的保護類型。
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET Document doc = new Document(inputFileName); ProtectionType protectionType = doc.ProtectionType;
注釋在文檔樹中表示為Comment類的對象。您可以像Aspose.Words文檔對象模型中的任何其他節點一樣以編程方式添加,刪除或修改注釋。Comment是一個復合節點,可以包含構成注釋文本的段落和表格。Comment類還提供對注釋作者的姓名和首字母的訪問。
在Microsoft Word中打開文檔時,可以控制文檔的視圖。例如,您可能希望切換到打印布局或更改縮放值。使用Document對象的Settings.ViewOptions屬性設置視圖選項。以下代碼顯示如何確保在Microsoft Word中打開時文檔以50%縮放顯示。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); // Load the template document. Document doc = new Document(dataDir + "TestFile.doc"); // Set view option. doc.ViewOptions.ViewType = ViewType.PageLayout; doc.ViewOptions.ZoomPercent = 50; dataDir = dataDir + "TestFile.SetZoom_out.doc"; // Save the finished document. doc.Save(dataDir);
想要購買正版授權,或者獲取更多Aspose.Words相關信息的朋友可以點擊" "~
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn