-
Notifications
You must be signed in to change notification settings - Fork 0
/
SubDocumentHelper.cs
58 lines (57 loc) · 2.43 KB
/
SubDocumentHelper.cs
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
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SubDocumentIterator
{
public static class SubDocumentHelper
{
public delegate void SubDocumentDelegate(SubDocument subDocument);
public static void ForEachSubDocument(this Document document, SubDocumentDelegate subDocumentProcessor)
{
subDocumentProcessor(document);
ProcessShapes(document.Shapes, subDocumentProcessor);
ProcessComments(document.Comments, subDocumentProcessor);
foreach (Section section in document.Sections)
{
ProcessSection(section, HeaderFooterType.First, subDocumentProcessor);
ProcessSection(section, HeaderFooterType.Odd, subDocumentProcessor);
ProcessSection(section, HeaderFooterType.Even, subDocumentProcessor);
}
}
private static void ProcessSection(Section section, HeaderFooterType headerFooterType, SubDocumentDelegate subDocumentProcessor)
{
if (section.HasHeader(headerFooterType))
{
SubDocument header = section.BeginUpdateHeader(headerFooterType);
subDocumentProcessor(header);
ProcessShapes(header.Shapes, subDocumentProcessor);
section.EndUpdateHeader(header);
}
if (section.HasFooter(headerFooterType))
{
SubDocument footer = section.BeginUpdateFooter(headerFooterType);
subDocumentProcessor(footer);
ProcessShapes(footer.Shapes, subDocumentProcessor);
section.EndUpdateFooter(footer);
}
}
private static void ProcessShapes(ShapeCollection shapes, SubDocumentDelegate subDocumentProcessor)
{
foreach (Shape shape in shapes)
if (shape.ShapeFormat.TextBox != null)
subDocumentProcessor(shape.ShapeFormat.TextBox.Document);
}
private static void ProcessComments(CommentCollection comments, SubDocumentDelegate subDocumentProcessor)
{
foreach (Comment comment in comments)
{
SubDocument commentSubDocument = comment.BeginUpdate();
subDocumentProcessor(commentSubDocument);
comment.EndUpdate(commentSubDocument);
}
}
}
}