Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/spreadsheet/preview: fix an issue
Adorian Doran31eab3c5998a
diff --git a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts b/packages/commons/src/lib/spreadsheet/render_to_html.spec.tsindex 664f5a95c2..8d85c8f33f 100644--- a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts+++ b/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts@@ -1998,6 +1998,36 @@ describe("renderSpreadsheetToHtml", () => {expect(banner(16383, 16384)).toContain(`colspan="4"`);});+ it("lets a tall merge widen the grid unless it was applied to entire columns", () => {+ const tall = (endRow: number, rowCount: number) => renderSpreadsheetToHtml(JSON.stringify({+ version: 1,+ workbook: {+ sheetOrder: ["s1"],+ styles: {},+ sheets: {+ s1: {+ id: "s1",+ name: "Sheet1",+ hidden: 0,+ mergeData: [{ startRow: 0, endRow, startColumn: 0, endColumn: 0 }],+ cellData: { "0": { "0": { v: "Side", t: 1 }, "1": { v: "a", t: 1 } }, "1": { "1": { v: "b", t: 1 } } },+ rowData: {},+ columnData: {},+ rowCount,+ columnCount: 20+ }+ }+ }+ }));++ // Merged by hand down a sheet shorter than the rows one starts with: the span is kept.+ expect(tall(49, 50)).toContain(`rowspan="50"`);++ // Applied to entire columns, so it covers at least those rows and is clamped to the content.+ expect(tall(999, 1000)).toContain(`rowspan="2"`);+ expect(tall(1048575, 1000)).toContain(`rowspan="2"`);+ });+it("counts a border as structure the grid has to reach, but not a fill", () => {const beyond = (style: unknown) => renderSpreadsheetToHtml(JSON.stringify({version: 1,diff --git a/packages/commons/src/lib/spreadsheet/render_to_html.ts b/packages/commons/src/lib/spreadsheet/render_to_html.tsindex 59d1ae881c..57e72e96a0 100644--- a/packages/commons/src/lib/spreadsheet/render_to_html.ts+++ b/packages/commons/src/lib/spreadsheet/render_to_html.ts@@ -764,7 +764,8 @@ function cellPadding(style: IStyleData | null): Required<IPaddingData> {* Across, that gesture is recognised by the sheet declaring every column Excel has: a banner merged* by hand stops well short of that, and keeps widening the grid as any other merge does. Down, the* same test is not available, because a sheet's row count is capped at the rows it uses rather than- * carried over from the file, so a merge reaching the last declared row is taken as the gesture.+ * carried over from the file. So a merge is taken as the gesture there when it reaches the last+ * declared row *and* covers at least the rows every sheet starts with, which no one merges by hand.*/function boundingMerges(mergeData: IRange[], sheet: IWorksheetData): IRange[] {const columnCount = sheet.columnCount ?? 0;@@ -772,9 +773,12 @@ function boundingMerges(mergeData: IRange[], sheet: IWorksheetData): IRange[] {return mergeData.filter((range) =>!(columnCount >= EXCEL_COLUMN_COUNT && range.startColumn === 0 && range.endColumn >= columnCount - 1)- && !(lastRow > 0 && range.startRow === 0 && range.endRow >= lastRow));+ && !(range.startRow === 0 && range.endRow >= lastRow && range.endRow - range.startRow + 1 >= DEFAULT_ROW_COUNT));}+/** The rows a sheet starts with, which both importers floor at and the editor creates. */+const DEFAULT_ROW_COUNT = 1000;+/** The columns an Excel sheet has, which only a sheet formatted across all of them declares. */const EXCEL_COLUMN_COUNT = 16384;