From 848fed883f8ed44b692421722a72f9abb4284755 Mon Sep 17 00:00:00 2001 From: MVilaH <124970615+MVilaH@users.noreply.github.com> Date: Wed, 14 Jan 2026 22:33:46 -0500 Subject: [PATCH 1/3] recalculating section dimensions for rowSpan recalculate the dimensions of the sections to return their exact size if you have to use rowSpan in head or foot or both since otherwise it increases the virtual size of the table and creates a new page before you have arrived has occupied the space established in the margins of the sheet. --- src/models.ts | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/models.ts b/src/models.ts index 3f50ea52..73321990 100644 --- a/src/models.ts +++ b/src/models.ts @@ -93,17 +93,27 @@ export class Table { } getHeadHeight(columns: Column[]) { - return this.head.reduce( - (acc, row) => acc + row.getMaxCellHeight(columns), - 0, - ) + var rowSpan = 0; + return this.head.reduce((acc, row) => { + if(rowSpan === 0){ + rowSpan = row.getMaxRowSpan(columns) - 1; + return acc + row.getMaxCellHeight(columns); + } + rowSpan-- + return acc + }, 0); } getFootHeight(columns: Column[]) { - return this.foot.reduce( - (acc, row) => acc + row.getMaxCellHeight(columns), - 0, - ) + var rowSpan = 0; + return this.foot.reduce((acc, row) => { + if(rowSpan === 0){ + rowSpan = row.getMaxRowSpan(columns) - 1; + return acc + row.getMaxCellHeight(columns); + } + rowSpan-- + return acc + }, 0); } allRows() { @@ -193,6 +203,13 @@ export class Row { ) } + getMaxRowSpan(columns: Column[]) { + return columns.reduce( + (acc, column) => Math.max(acc, this.cells[column.index]?.rowSpan || 0), + 0, + ) + } + hasRowSpan(columns: Column[]) { return ( columns.filter((column: Column) => { From bc810f6a5d4b5aba63bc8f15263b05595b4a508d Mon Sep 17 00:00:00 2001 From: MVilaH <124970615+MVilaH@users.noreply.github.com> Date: Sun, 18 Jan 2026 08:56:54 -0500 Subject: [PATCH 2/3] Update optimization --- src/models.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/models.ts b/src/models.ts index 73321990..1c98f564 100644 --- a/src/models.ts +++ b/src/models.ts @@ -93,27 +93,27 @@ export class Table { } getHeadHeight(columns: Column[]) { - var rowSpan = 0; + var rowSpan = 0 return this.head.reduce((acc, row) => { if(rowSpan === 0){ - rowSpan = row.getMaxRowSpan(columns) - 1; - return acc + row.getMaxCellHeight(columns); + rowSpan = row.getMaxRowSpan(columns) + return acc + row.getMaxCellHeight(columns) } rowSpan-- return acc - }, 0); + }, 0) } getFootHeight(columns: Column[]) { - var rowSpan = 0; + var rowSpan = 0 return this.foot.reduce((acc, row) => { if(rowSpan === 0){ - rowSpan = row.getMaxRowSpan(columns) - 1; - return acc + row.getMaxCellHeight(columns); + rowSpan = row.getMaxRowSpan(columns) + return acc + row.getMaxCellHeight(columns) } rowSpan-- return acc - }, 0); + }, 0) } allRows() { @@ -207,7 +207,7 @@ export class Row { return columns.reduce( (acc, column) => Math.max(acc, this.cells[column.index]?.rowSpan || 0), 0, - ) + ) - 1 } hasRowSpan(columns: Column[]) { From c77b92ce0f9b395c5854933c00c405b0f0ad9aff Mon Sep 17 00:00:00 2001 From: MVilaH <124970615+MVilaH@users.noreply.github.com> Date: Tue, 20 Jan 2026 10:48:25 -0500 Subject: [PATCH 3/3] Update improve code readability and efficiency. --- src/models.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/models.ts b/src/models.ts index 1c98f564..c2373e04 100644 --- a/src/models.ts +++ b/src/models.ts @@ -93,9 +93,9 @@ export class Table { } getHeadHeight(columns: Column[]) { - var rowSpan = 0 + var rowSpan = 1 return this.head.reduce((acc, row) => { - if(rowSpan === 0){ + if(rowSpan === 1){ rowSpan = row.getMaxRowSpan(columns) return acc + row.getMaxCellHeight(columns) } @@ -105,9 +105,9 @@ export class Table { } getFootHeight(columns: Column[]) { - var rowSpan = 0 + var rowSpan = 1 return this.foot.reduce((acc, row) => { - if(rowSpan === 0){ + if(rowSpan === 1){ rowSpan = row.getMaxRowSpan(columns) return acc + row.getMaxCellHeight(columns) } @@ -207,7 +207,7 @@ export class Row { return columns.reduce( (acc, column) => Math.max(acc, this.cells[column.index]?.rowSpan || 0), 0, - ) - 1 + ) } hasRowSpan(columns: Column[]) {