Skip to content

Commit 8553f06

Browse files
committed
initial commit
1 parent ad57332 commit 8553f06

File tree

4 files changed

+201
-0
lines changed

4 files changed

+201
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace DocumentFormat.OpenXml.Wordprocessing
7+
{
8+
public partial class Table
9+
{
10+
/// <summary>
11+
/// Gets or sets the TableProperties.
12+
/// </summary>
13+
public TableProperties? TableProperties
14+
{
15+
get => GetElement(Wordprocessing.TableProperties.ElementType) as TableProperties;
16+
set => SetElement(value, Wordprocessing.TableProperties.ElementType);
17+
}
18+
19+
/// <summary>
20+
/// Gets or sets the TableGrid.
21+
/// </summary>
22+
public TableGrid? TableGrid
23+
{
24+
get => GetElement(Wordprocessing.TableGrid.ElementType) as TableGrid;
25+
set => SetElement(value, Wordprocessing.TableGrid.ElementType);
26+
}
27+
28+
/// <summary>
29+
/// Gets the collection of TableRow elements.
30+
/// </summary>
31+
public IEnumerable<TableRow>? TableRow
32+
{
33+
get
34+
{
35+
foreach (var element in Elements<TableRow>())
36+
{
37+
yield return element;
38+
}
39+
}
40+
}
41+
}
42+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace DocumentFormat.OpenXml.Wordprocessing
7+
{
8+
/// <summary>
9+
/// Represents a table row in a Wordprocessing document.
10+
/// </summary>
11+
public partial class TableRow
12+
{
13+
/// <summary>
14+
/// Gets the collection of table cells within the table row.
15+
/// </summary>
16+
public IEnumerable<TableCell>? TableCell
17+
{
18+
get
19+
{
20+
foreach (var element in Elements<TableCell>())
21+
{
22+
yield return element;
23+
}
24+
}
25+
}
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Linq;
5+
using Xunit;
6+
7+
namespace DocumentFormat.OpenXml.Wordprocessing
8+
{
9+
public class TableRowTest
10+
{
11+
[Fact]
12+
public void TableCellTest()
13+
{
14+
// Arrange
15+
Table table = new Table();
16+
17+
// Create table rows and cells
18+
TableRow tr = table.AppendChild(new TableRow());
19+
TableCell tc1 = tr.AppendChild(new TableCell(new TableCellProperties(
20+
new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" })));
21+
tc1.AppendChild(new Paragraph(new Run(new Text("Text to test"))));
22+
23+
// Assert
24+
foreach (var cell in tr.TableCell.ToList())
25+
{
26+
Assert.IsType<TableCell>(cell);
27+
Assert.Equal(tc1, cell);
28+
Assert.Equal("Text to test", cell.InnerText);
29+
}
30+
}
31+
}
32+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using Xunit;
8+
9+
namespace DocumentFormat.OpenXml.Wordprocessing
10+
{
11+
public class TableTests
12+
{
13+
[Fact]
14+
public void TablePropertiesGetterAndSetterTest()
15+
{
16+
// Arrange
17+
var table = new Table();
18+
var tableProperties = new TableProperties(new TableBorders(
19+
new TopBorder()
20+
{
21+
Val =
22+
new EnumValue<BorderValues>(BorderValues.Single),
23+
Size = 24,
24+
},
25+
new BottomBorder()
26+
{
27+
Val =
28+
new EnumValue<BorderValues>(BorderValues.Single),
29+
Size = 24,
30+
}));
31+
32+
// Act
33+
table.AppendChild(tableProperties);
34+
35+
// Assert
36+
Assert.NotNull(table.TableProperties);
37+
Assert.Equal(tableProperties, table.TableProperties);
38+
}
39+
40+
[Fact]
41+
public void TableGridsGetterAndSetterTest()
42+
{
43+
// Arrange
44+
var table = new Table();
45+
var tableGrid = new TableGrid(new GridColumn(), new GridColumn(), new GridColumn());
46+
47+
// Act
48+
table.AppendChild(tableGrid);
49+
50+
// Assert
51+
Assert.NotNull(table.TableGrid);
52+
Assert.Equal(tableGrid, table.TableGrid);
53+
}
54+
55+
[Fact]
56+
public void TableRowTest()
57+
{
58+
// Arrange
59+
Table table = new Table();
60+
61+
// Create table rows and cells
62+
TableRow tr = table.AppendChild(new TableRow());
63+
TableCell tc1 = tr.AppendChild(new TableCell(new TableCellProperties(
64+
new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" })));
65+
tc1.AppendChild(new Paragraph(new Run(new Text("Text 1"))));
66+
67+
// Specify the table cell content.
68+
TableCell tc2 = tr.AppendChild(new TableCell(new TableCellProperties(
69+
new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" })));
70+
tc2.AppendChild(new Paragraph(new Run(new Text("Text 2"))));
71+
72+
// Create table rows and cells
73+
TableRow tr2 = table.AppendChild(new TableRow());
74+
TableCell tc3 = tr2.AppendChild(new TableCell(new TableCellProperties(
75+
new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" })));
76+
tc3.AppendChild(new Paragraph(new Run(new Text("Text 3"))));
77+
78+
// Specify the table cell content.
79+
TableCell tc4 = tr2.AppendChild(new TableCell(new TableCellProperties(
80+
new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" })));
81+
tc4.AppendChild(new Paragraph(new Run(new Text("Text 4"))));
82+
83+
// List to store table rows
84+
List<TableRow> rows = [tr, tr2];
85+
86+
// Assert
87+
Assert.NotNull(table.TableRow);
88+
TableRow tableRow = new TableRow();
89+
Assert.Equal(rows.Count, table.TableRow.Count());
90+
int i = 0;
91+
foreach (var row in table.TableRow.ToList())
92+
{
93+
Console.WriteLine(row.InnerText);
94+
Assert.IsType<TableRow>(row);
95+
Assert.Equal(rows[i], row);
96+
i++;
97+
}
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)