forked from totravel/minidocx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraverse.cpp
49 lines (39 loc) · 1.28 KB
/
traverse.cpp
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
#include <iostream>
#include "minidocx.hpp"
int main()
{
docx::Document doc;
// Section 1
doc.AppendParagraph("This is the 1st paragraph.");
doc.AppendParagraph("This is the 2nd paragraph.");
doc.AppendParagraph("This is the 3rd paragraph.");
auto p = doc.AppendSectionBreak();
p.AppendRun("This is the 1st run. ");
p.AppendRun("This is the 2nd run. ");
auto r = p.AppendRun();
r.AppendText("This is the 1st text. ");
r.AppendText("This is the 2nd text. ");
r.AppendText("This is the 3rd text.");
// Section 2
doc.AppendParagraph("This is the 5th paragraph.");
doc.AppendParagraph("This is the 6th paragraph.");
doc.AppendSectionBreak().AppendRun("This is the 7th paragraph.");
// Section 3
doc.AppendParagraph("This is the 8th paragraph.");
doc.AppendParagraph("This is the 9th paragraph.");
for (auto p = doc.FirstParagraph(); p; p = p.Next()) {
std::cout << "paragraph: \n";
for (auto r = p.FirstRun(); r; r = r.Next()) {
std::cout << "run: " << r.GetText() << std::endl;
}
}
auto s2 = doc.FirstSection().Next();
auto last = s2.LastParagraph();
for (auto p = s2.FirstParagraph(); p; p = p.Next()) {
p.SetAlignment(docx::Paragraph::Alignment::Centered);
if (p == last) break;
}
doc.Save("traverse.docx");
return 0;
}