Skip to content

Commit

Permalink
Fixes wrong implementation of repeat header
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Jun 20, 2024
1 parent 63cfda9 commit 7b895e3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
11 changes: 3 additions & 8 deletions OfficeIMO.Tests/Word.Tables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public void Test_CreatingWordDocumentWithTables() {

Assert.True(wordTable.RepeatHeaderRowAtTheTopOfEachPage == false);

Assert.True(wordTable.LastRow.RepeatHeaderRowAtTheTopOfEachPage == false);
foreach (var row in wordTable.Rows) {
Assert.True(row.RepeatHeaderRowAtTheTopOfEachPage == false);
}
Expand All @@ -35,10 +34,8 @@ public void Test_CreatingWordDocumentWithTables() {

Assert.True(wordTable.RepeatHeaderRowAtTheTopOfEachPage == true);

Assert.True(wordTable.LastRow.RepeatHeaderRowAtTheTopOfEachPage == true);

foreach (var row in wordTable.Rows) {
Assert.True(row.RepeatHeaderRowAtTheTopOfEachPage == true);
foreach (var row in wordTable.Rows.Skip(1)) {
Assert.True(row.RepeatHeaderRowAtTheTopOfEachPage == false);
}

Assert.True(wordTable.Rows.Count == 3);
Expand All @@ -47,9 +44,7 @@ public void Test_CreatingWordDocumentWithTables() {

Assert.True(wordTable.Rows.Count == 5);

foreach (var row in wordTable.Rows) {
Assert.True(row.RepeatHeaderRowAtTheTopOfEachPage == true);
}
Assert.True(wordTable.Rows[0].RepeatHeaderRowAtTheTopOfEachPage == true);

Assert.True(wordTable.Rows[2].Cells[0].Paragraphs[0].Text == "Test 3", "Text in table matches. Actual text: " + wordTable.Rows[2].Cells[0].Paragraphs[0].Text);
Assert.True(wordTable.Paragraphs.Count == 16, "Number of paragraphs during creation in table is wrong. Current: " + wordTable.Paragraphs.Count);
Expand Down
13 changes: 2 additions & 11 deletions OfficeIMO.Word/WordTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ public bool? ConditionalFormattingNoVerticalBand {
/// </summary>
public bool RepeatHeaderRowAtTheTopOfEachPage {
get => Rows[0].RepeatHeaderRowAtTheTopOfEachPage;
set {
foreach (var row in Rows) {
row.RepeatHeaderRowAtTheTopOfEachPage = value;
}
}
set => Rows[0].RepeatHeaderRowAtTheTopOfEachPage = value;
}

public int RowsCount => this.Rows.Count;
Expand Down Expand Up @@ -418,12 +414,7 @@ internal WordTable(WordDocument document, Header header, int rows, int columns,
/// </summary>
/// <param name="cellsCount"></param>
public WordTableRow AddRow(int cellsCount = 0) {
// when adding a row to the table, we need to check if the last row has RepeatHeaderRowAtTheTopOfEachPage set
// if it does, we need to set it for the new row as well
var repeatHeaders = this.LastRow.RepeatHeaderRowAtTheTopOfEachPage;
WordTableRow row = new WordTableRow(_document, this) {
RepeatHeaderRowAtTheTopOfEachPage = repeatHeaders
};
WordTableRow row = new WordTableRow(_document, this);
_table.Append(row._tableRow);
AddCells(row, cellsCount);
return row;
Expand Down

0 comments on commit 7b895e3

Please sign in to comment.