Skip to content

Commit

Permalink
Merge pull request #234 from EvotecIT/FixHeader
Browse files Browse the repository at this point in the history
Fixes wrong implementation of repeat header
  • Loading branch information
PrzemyslawKlys authored Jun 21, 2024
2 parents 63cfda9 + 0b72041 commit 752dc6c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 20 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
2 changes: 1 addition & 1 deletion OfficeIMO.Word/OfficeIMO.Word.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>OfficeIMO.Word</AssemblyName>
<AssemblyTitle>OfficeIMO.Word</AssemblyTitle>

<VersionPrefix>0.16.0</VersionPrefix>
<VersionPrefix>0.17.0</VersionPrefix>
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`Windows`))' ">netstandard2.0;netstandard2.1;net472;net48;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks Condition=" '$([MSBuild]::IsOsPlatform(`OSX`))' Or '$([MSBuild]::IsOsPlatform(`Linux`))' ">net6.0;net7.0;net8.0</TargetFrameworks>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
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 752dc6c

Please sign in to comment.