Skip to content

Commit 4a20f70

Browse files
Added sample
1 parent cbfb9e2 commit 4a20f70

4 files changed

Lines changed: 37 additions & 22 deletions

File tree

Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Data/Table.html

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
<table>
22
<thead>
33
<tr>
4-
<td>Nummer</td>
4+
<td>Number</td>
55
<td>Name</td>
6-
<td>Abschluss</td>
7-
<td>Dauer</td>
6+
<td>Completion Date</td>
7+
<td>Duration</td>
88
<td>Extras</td>
99
</tr>
1010
</thead>
1111
<tbody>
1212
<tr>
1313
<td>1</td>
14-
<td>Vertrag 1</td>
15-
<td>15.08.2023</td>
16-
<td>10 Jahre</td>
14+
<td>Contract A</td>
15+
<td>01.01.2022</td>
16+
<td>5 Years</td>
1717
<td>
1818
<ul>
19-
<li>Extra 1</li>
20-
<li>Extra 2</li>
19+
<li>Feature 1</li>
20+
<li>Feature 2</li>
2121
</ul>
2222
</td>
2323
</tr>
2424
<tr>
2525
<td>2</td>
26-
<td>Vertrag 2</td>
27-
<td>15.08.2023</td>
28-
<td>12 Jahre</td>
26+
<td>Contract B</td>
27+
<td>15.06.2023</td>
28+
<td>3 Years</td>
2929
<td>
3030
<ol>
31-
<li>Extra 1</li>
32-
<li>Extra 2</li>
31+
<li>Option 1</li>
32+
<li>Option 2</li>
3333
</ol>
3434
</td>
3535
</tr>
3636
<tr>
3737
<td>3</td>
38-
<td>Vertrag 3</td>
39-
<td>15.08.2023</td>
40-
<td>100 Jahre</td>
38+
<td>Contract C</td>
39+
<td>20.03.2024</td>
40+
<td>7 Years</td>
4141
<td>
42-
<p style="color: red">KEINE EXTRAS</p>
42+
<p style="color: red">No Additional Features</p>
4343
</td>
4444
</tr>
4545
</tbody>
Binary file not shown.
Binary file not shown.

Tables/Apply_Styles_For_Inserted_Tables/.NET/Apply-Styles-For-Inserted-Tables/Program.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,28 @@ static void Main(string[] args)
1818
resultDocument.LastSection.Body.InsertXHTML(html);
1919

2020
// Append table manually - this one applies the table style from the template
21+
var employees = new List<(string Id, string Name, string Department)>
22+
{
23+
("1001", "John", "Sales"),
24+
("1002", "Mary", "HR"),
25+
("1003", "David", "IT")
26+
};
27+
2128
IWTable table = resultDocument.LastSection.AddTable();
22-
//Specify the total number of rows and columns.
23-
table.ResetCells(2, 6);
29+
table.ResetCells(employees.Count + 1, 3);
30+
31+
// Header row
32+
table[0, 0].AddParagraph().AppendText("ID");
33+
table[0, 1].AddParagraph().AppendText("Name");
34+
table[0, 2].AddParagraph().AppendText("Department");
2435

25-
for (int rowIndex = 0; rowIndex < 2; rowIndex++)
26-
for (int columnIndex = 0; columnIndex < 6; columnIndex++)
27-
table.Rows[rowIndex].Cells[columnIndex].AddParagraph().Text = (rowIndex * columnIndex).ToString();
36+
// Data rows
37+
for (int i = 0; i < employees.Count; i++)
38+
{
39+
table[i + 1, 0].AddParagraph().AppendText(employees[i].Id);
40+
table[i + 1, 1].AddParagraph().AppendText(employees[i].Name);
41+
table[i + 1, 2].AddParagraph().AppendText(employees[i].Department);
42+
}
2843

2944
//Finds all the table in the Word document
3045
List<Entity> tableList = resultDocument.FindAllItemsByProperty(EntityType.Table, "EntityType", EntityType.Table.ToString());

0 commit comments

Comments
 (0)