访问修订版本
内容
[
隐藏
]在本分步指南中,我们将向您展示如何使用 Aspose.Words for .NET 访问 Word 文档的修订版本。我们将为您提供完整的源代码并向您展示如何格式化 markdown 输出。
步骤 1:加载文档
第一步是上传包含修订内容的文档。
Document doc = new Document(MyDir + "Revisions.docx");
doc.UpdateListLabels();
第 2 步:访问修订版本
我们现在将讨论该文件的修订版本。
doc.RevisionsView = RevisionsView.Final;
步骤 3:浏览修订版本
接下来,我们将循环遍历文档中现有的修订,并显示列表项段落的具体信息。
foreach (Revision revision in doc.Revisions)
{
if (revision.ParentNode.NodeType == NodeType.Paragraph)
{
Paragraph paragraph = (Paragraph)revision.ParentNode;
if (paragraph.IsListItem)
{
Console.WriteLine(paragraph.ListLabel.LabelString);
Console.WriteLine(paragraph.ListFormat.ListLevel);
}
}
}
使用 Aspose.Words for .NET 的 Access Revised Version 示例源代码
以下是使用 Aspose.Words for .NET 访问文档修订版本的完整源代码:
Document doc = new Document(MyDir + "Revisions.docx");
doc.UpdateListLabels();
//切换到文档的修订版本。
doc.RevisionsView = RevisionsView.Final;
foreach (Revision revision in doc.Revisions)
{
if (revision.ParentNode.NodeType == NodeType.Paragraph)
{
Paragraph paragraph = (Paragraph)revision.ParentNode;
if (paragraph.IsListItem)
{
Console.WriteLine(paragraph.ListLabel.LabelString);
Console.WriteLine(paragraph.ListFormat.ListLevel);
}
}
}
结论
在本教程中,我们学习了如何使用 Aspose.Words for .NET 访问 Word 文档的修订版本。通过加载文档、导航到修订版本并浏览修订版本,我们能够获取列表项段落的具体信息。Aspose.Words for .NET 提供了强大的功能来操作 Word 文档,包括访问评论。现在,您可以使用这些知识使用 Aspose.Words for .NET 访问您自己的 Word 文档的修订版本。
常见问题解答
问:如何将修订后的文档加载到 Aspose.Words for .NET 中?
答:使用Document
Aspose.Words for .NET 类用于从包含修订的文件中加载文档。您可以指定完整的文档路径。
Document doc = new Document("path/to/the/document.docx");
问:如何在 Aspose.Words for .NET 中访问文档的修订版本?
答:使用RevisionsView
的财产Document
对象来访问文档的修订版本。您可以设置RevisionsView
财产RevisionsView.Final
显示未经修改的最终版本。
doc.RevisionsView = RevisionsView.Final;
问:如何浏览 Aspose.Words for .NET 中的文档修订?
答:使用foreach
循环遍历文档中存在的修订。您可以使用Revisions
的财产Document
对象来获取文档所有修订的集合。
foreach (Revision revision in doc.Revisions)
{
//在此处理每次修订
}
问:如何检查某个段落是否是 Aspose.Words for .NET 中的列表项?
答:使用IsListItem
的财产Paragraph
对象来检查段落是否为列表项。IsListItem
财产回报true
如果该段落是列表项,否则返回false
.
if (paragraph.IsListItem)
{
//该段落是列表项
}
else
{
//该段落不是列表项
}