-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload-a-document-start-tracking-insert-a-table-stop-tracking-then-accept-the-table-insertio.cs
More file actions
64 lines (56 loc) · 2.67 KB
/
Copy pathload-a-document-start-tracking-insert-a-table-stop-tracking-then-accept-the-table-insertio.cs
File metadata and controls
64 lines (56 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using Aspose.Words;
using Aspose.Words.Tables;
public class Program
{
public static void Main()
{
// Paths for the temporary original document and the final result.
const string originalPath = "original.docx";
const string finalPath = "final.docx";
// -----------------------------------------------------------------
// 1. Create a simple document and save it – this provides a file to load.
// -----------------------------------------------------------------
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Initial content.");
doc.Save(originalPath);
// -----------------------------------------------------------------
// 2. Load the document we just created.
// -----------------------------------------------------------------
Document loadedDoc = new Document(originalPath);
DocumentBuilder loadedBuilder = new DocumentBuilder(loadedDoc);
// -----------------------------------------------------------------
// 3. Start tracking revisions.
// -----------------------------------------------------------------
loadedDoc.StartTrackRevisions("John Doe", DateTime.Now);
// -----------------------------------------------------------------
// 4. Insert a table while tracking is active – this creates an insertion revision.
// -----------------------------------------------------------------
loadedBuilder.StartTable();
loadedBuilder.InsertCell();
loadedBuilder.Write("Cell 1");
loadedBuilder.InsertCell();
loadedBuilder.Write("Cell 2");
loadedBuilder.EndRow();
loadedBuilder.EndTable();
// -----------------------------------------------------------------
// 5. Stop tracking revisions.
// -----------------------------------------------------------------
loadedDoc.StopTrackRevisions();
// -----------------------------------------------------------------
// 6. Accept only the table insertion revision(s).
// -----------------------------------------------------------------
foreach (Revision rev in loadedDoc.Revisions)
{
if (rev.RevisionType == RevisionType.Insertion && rev.ParentNode.NodeType == NodeType.Table)
{
rev.Accept();
}
}
// -----------------------------------------------------------------
// 7. Save the resulting document.
// -----------------------------------------------------------------
loadedDoc.Save(finalPath);
}
}