-
-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathTableBorderTestHelper.cs
More file actions
40 lines (39 loc) · 1.7 KB
/
TableBorderTestHelper.cs
File metadata and controls
40 lines (39 loc) · 1.7 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
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace MiniWordTests
{
internal static class TableBorderTestHelper
{
/// <summary>
/// Creates a minimal Word template that contains a table with:
/// <list type="bullet">
/// <item>A header row with static text.</item>
/// <item>A data row with <c>{{Items.Name}}</c> and <c>{{Items.Value}}</c> placeholders.</item>
/// <item>A dedicated border-control row with a <c>{{TableBorder}}</c> placeholder.</item>
/// </list>
/// </summary>
internal static void CreateTableBorderTemplate(string filePath)
{
using var doc = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document);
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document(
new Body(
new Table(
new TableRow(
new TableCell(new Paragraph(new Run(new Text("Name")))),
new TableCell(new Paragraph(new Run(new Text("Value")))),
new TableCell(new Paragraph(new Run(new Text("{{TableBorder}}"))))
),
new TableRow(
new TableCell(new Paragraph(new Run(new Text("{{Items.Name}}")))),
new TableCell(new Paragraph(new Run(new Text("{{Items.Value}}")))),
new TableCell(new Paragraph(new Run(new Text(""))))
)
)
)
);
doc.Save();
}
}
}