-
Notifications
You must be signed in to change notification settings - Fork 573
Provide Table Explicit Properties - #1149 #1921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8553f06
initial commit
mkaszewiak 41bce6a
Merge branch 'main' into add-table-properties-1149
mkaszewiak 33c831b
comments applied
mkaszewiak 393a0bd
Merge branch 'add-table-properties-1149' of https://github.com/mkasze…
mkaszewiak f7052a4
Merge branch 'main' into add-table-properties-1149
mikeebowen 81b6f5d
Merge branch 'main' into add-table-properties-1149
mkaszewiak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace DocumentFormat.OpenXml.Wordprocessing | ||
| { | ||
| public partial class Table | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the TableProperties. | ||
| /// </summary> | ||
| public TableProperties? TableProperties | ||
| { | ||
| get => GetElement(Wordprocessing.TableProperties.ElementType) as TableProperties; | ||
| set => SetElement(value, Wordprocessing.TableProperties.ElementType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the TableGrid. | ||
| /// </summary> | ||
| public TableGrid? TableGrid | ||
| { | ||
| get => GetElement(Wordprocessing.TableGrid.ElementType) as TableGrid; | ||
| set => SetElement(value, Wordprocessing.TableGrid.ElementType); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the collection of TableRow elements. | ||
| /// </summary> | ||
| public IEnumerable<TableRow>? TableRow | ||
| { | ||
| get | ||
| { | ||
| foreach (var element in Elements<TableRow>()) | ||
| { | ||
| yield return element; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
src/DocumentFormat.OpenXml/Schema/Wordprocessing/TableRow.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections.Generic; | ||
|
|
||
| namespace DocumentFormat.OpenXml.Wordprocessing | ||
| { | ||
| /// <summary> | ||
| /// Represents a table row in a Wordprocessing document. | ||
| /// </summary> | ||
| public partial class TableRow | ||
| { | ||
| /// <summary> | ||
| /// Gets the collection of table cells within the table row. | ||
| /// </summary> | ||
| public IEnumerable<TableCell>? TableCell | ||
| { | ||
| get | ||
| { | ||
| foreach (var element in Elements<TableCell>()) | ||
| { | ||
| yield return element; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
32 changes: 32 additions & 0 deletions
32
test/DocumentFormat.OpenXml.Tests/Wordprocessing/TableRowTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Linq; | ||
| using Xunit; | ||
|
|
||
| namespace DocumentFormat.OpenXml.Wordprocessing | ||
| { | ||
| public class TableRowTest | ||
| { | ||
| [Fact] | ||
| public void TableCellTest() | ||
| { | ||
| // Arrange | ||
| Table table = new Table(); | ||
|
|
||
| // Create table rows and cells | ||
| TableRow tr = table.AppendChild(new TableRow()); | ||
| TableCell tc1 = tr.AppendChild(new TableCell(new TableCellProperties( | ||
| new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }))); | ||
| tc1.AppendChild(new Paragraph(new Run(new Text("Text to test")))); | ||
|
|
||
| // Assert | ||
| foreach (var cell in tr.TableCell.ToList()) | ||
| { | ||
| Assert.IsType<TableCell>(cell); | ||
| Assert.Equal(tc1, cell); | ||
| Assert.Equal("Text to test", cell.InnerText); | ||
| } | ||
| } | ||
| } | ||
| } |
100 changes: 100 additions & 0 deletions
100
test/DocumentFormat.OpenXml.Tests/Wordprocessing/TableTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Xunit; | ||
|
|
||
| namespace DocumentFormat.OpenXml.Wordprocessing | ||
| { | ||
| public class TableTests | ||
| { | ||
| [Fact] | ||
| public void TablePropertiesGetterAndSetterTest() | ||
| { | ||
| // Arrange | ||
| var table = new Table(); | ||
| var tableProperties = new TableProperties(new TableBorders( | ||
| new TopBorder() | ||
| { | ||
| Val = | ||
| new EnumValue<BorderValues>(BorderValues.Single), | ||
| Size = 24, | ||
| }, | ||
| new BottomBorder() | ||
| { | ||
| Val = | ||
| new EnumValue<BorderValues>(BorderValues.Single), | ||
| Size = 24, | ||
| })); | ||
|
|
||
| // Act | ||
| table.AppendChild(tableProperties); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(table.TableProperties); | ||
| Assert.Equal(tableProperties, table.TableProperties); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TableGridsGetterAndSetterTest() | ||
| { | ||
| // Arrange | ||
| var table = new Table(); | ||
| var tableGrid = new TableGrid(new GridColumn(), new GridColumn(), new GridColumn()); | ||
|
|
||
| // Act | ||
| table.AppendChild(tableGrid); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(table.TableGrid); | ||
| Assert.Equal(tableGrid, table.TableGrid); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void TableRowTest() | ||
| { | ||
| // Arrange | ||
| Table table = new Table(); | ||
|
|
||
| // Create table rows and cells | ||
| TableRow tr = table.AppendChild(new TableRow()); | ||
| TableCell tc1 = tr.AppendChild(new TableCell(new TableCellProperties( | ||
| new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }))); | ||
| tc1.AppendChild(new Paragraph(new Run(new Text("Text 1")))); | ||
|
|
||
| // Specify the table cell content. | ||
| TableCell tc2 = tr.AppendChild(new TableCell(new TableCellProperties( | ||
| new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }))); | ||
| tc2.AppendChild(new Paragraph(new Run(new Text("Text 2")))); | ||
|
|
||
| // Create table rows and cells | ||
| TableRow tr2 = table.AppendChild(new TableRow()); | ||
| TableCell tc3 = tr2.AppendChild(new TableCell(new TableCellProperties( | ||
| new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }))); | ||
| tc3.AppendChild(new Paragraph(new Run(new Text("Text 3")))); | ||
|
|
||
| // Specify the table cell content. | ||
| TableCell tc4 = tr2.AppendChild(new TableCell(new TableCellProperties( | ||
| new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2400" }))); | ||
| tc4.AppendChild(new Paragraph(new Run(new Text("Text 4")))); | ||
|
|
||
| // List to store table rows | ||
| List<TableRow> rows = [tr, tr2]; | ||
|
|
||
| // Assert | ||
| Assert.NotNull(table.TableRow); | ||
| TableRow tableRow = new TableRow(); | ||
| Assert.Equal(rows.Count, table.TableRow.Count()); | ||
| int i = 0; | ||
| foreach (var row in table.TableRow.ToList()) | ||
| { | ||
| Console.WriteLine(row.InnerText); | ||
| Assert.IsType<TableRow>(row); | ||
| Assert.Equal(rows[i], row); | ||
| i++; | ||
| } | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is an IEnumerable, I think plural
TableCellswould be a better nameThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And do we currently return nullable enumerables? I'd prefer to return an empty enumerable, but we should follow whatever the pattern is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@twsouthwick I applied changes you and Mike recommended can I have this PR re reviewed/approved Thanks