这篇简短的教程介绍了如何使用 C# 跟踪 Word 中的更改。它提供了如何设置 IDE 来使用 Aspose.Words for .NET 的详细信息、步骤列表和示例代码,展示了如何在 Word 中启用更改跟踪 C#。您还将学习如何在处理文档时关闭跟踪并检查跟踪状态。
使用 C# 启用 Word 中的更改跟踪的步骤
- 设置 IDE 以使用 Aspose.Words for .NET 跟踪更改
- 创建一个新的 文档 并向其中添加一个表格
- 添加一行并插入一个单元格
- 使用 StartTrackRevisions() 方法开始在 Word 文档中跟踪更改
- 向文档中添加更多内容以进行跟踪
- 保存 Word 文件并在 MS Word 中打开以检查更改跟踪
这些步骤解释了如何使用 C# 跟踪 Word 中的更改。创建一个 Word 文件,添加一些内容,然后使用作者的姓名和日期/时间调用 StartTrackRevisions() 方法以开始跟踪更改。在保存 Word 文件到磁盘之前添加一些内容,并在 MS Word 中打开它以查看更改。
使用 C# 跟踪 Word DOC 中的更改的代码
using System; | |
using Aspose.Words; | |
using Aspose.Words.Tables; | |
namespace SimpleTableDocument | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
License lic = new License(); | |
lic.SetLicense("License.lic"); | |
Document wordDoc = new Document(); | |
Table table = new Table(wordDoc); | |
table.EnsureMinimum(); | |
Row row = new Row(wordDoc); | |
table.AppendChild(row); | |
Cell cell = new Cell(wordDoc); | |
row.AppendChild(cell); | |
wordDoc.StartTrackRevisions("The developer", DateTime.Now); | |
Paragraph paragraph = new Paragraph(wordDoc); | |
paragraph.AppendChild(new Run(wordDoc, "Sample text in the table cell.")); | |
cell.AppendChild(paragraph); | |
wordDoc.FirstSection.Body.AppendChild(table); | |
string outputFilePath = "SimpleTableDocument.docx"; | |
wordDoc.Save(outputFilePath); | |
Console.WriteLine("Document with a simple table created successfully: " + outputFilePath); | |
} | |
} | |
} |
此代码演示了如何使用 C# 在 Word 中使用更改跟踪。调用 StopTrackRevisions() 方法以在使用 API 处理文档时停止跟踪。使用 HasRevisions 标志检查文档是否有任何已跟踪的更改。
本文教会了我们如何开始和停止在 Word 文件中跟踪更改的过程。要将 PDF 文件转换为 EPUB,请参考文章 使用 C# 将 PDF 转换为 EPUB。