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 Doranee2649e6204e
diff --git a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts b/packages/commons/src/lib/spreadsheet/render_to_html.spec.tsindex 8d3d9ac25e..664f5a95c2 100644--- a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts+++ b/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts@@ -1968,6 +1968,36 @@ describe("renderSpreadsheetToHtml", () => {expect(html).toContain(`<col span="2" style="width:88px">`);});+ it("lets a merged banner widen the grid unless it was applied to entire rows", () => {+ const banner = (endColumn: number, columnCount: number) => renderSpreadsheetToHtml(JSON.stringify({+ version: 1,+ workbook: {+ sheetOrder: ["s1"],+ styles: {},+ sheets: {+ s1: {+ id: "s1",+ name: "Sheet1",+ hidden: 0,+ mergeData: [{ startRow: 0, endRow: 0, startColumn: 0, endColumn }],+ cellData: { "0": { "0": { v: "Banner", t: 1 } }, "1": { "0": { v: "a", t: 1 }, "3": { v: "d", t: 1 } } },+ rowData: {},+ columnData: {},+ rowCount: 1000,+ columnCount+ }+ }+ }+ }));++ // Merged by hand: the sheet declares only the columns it uses, so the banner keeps its span.+ expect(banner(25, 26)).toContain(`colspan="26"`);++ // Applied to entire rows: the sheet declares every column Excel has, and the banner is+ // clamped into the content rather than carrying the grid out to meet it.+ expect(banner(16383, 16384)).toContain(`colspan="4"`);+ });+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 7a044e5910..59d1ae881c 100644--- a/packages/commons/src/lib/spreadsheet/render_to_html.ts+++ b/packages/commons/src/lib/spreadsheet/render_to_html.ts@@ -757,20 +757,27 @@ function cellPadding(style: IStyleData | null): Required<IPaddingData> {}/**- * The merges that say something about how far a sheet reaches. One spanning the whole width or- * height of the grid was applied to entire rows or columns, which is a formatting gesture rather- * than a statement that the sheet runs to the last column Excel has, so it is left out and clamped- * into the content instead.+ * The merges that say something about how far a sheet reaches. One applied to entire rows or columns+ * is a formatting gesture rather than a statement that the sheet runs that far, so it is left out+ * and clamped into the content instead.+ *+ * 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.*/function boundingMerges(mergeData: IRange[], sheet: IWorksheetData): IRange[] {- const lastColumn = (sheet.columnCount ?? 0) - 1;+ const columnCount = sheet.columnCount ?? 0;const lastRow = (sheet.rowCount ?? 0) - 1;return mergeData.filter((range) =>- !(lastColumn > 0 && range.startColumn === 0 && range.endColumn >= lastColumn)+ !(columnCount >= EXCEL_COLUMN_COUNT && range.startColumn === 0 && range.endColumn >= columnCount - 1)&& !(lastRow > 0 && range.startRow === 0 && range.endRow >= lastRow));}+/** The columns an Excel sheet has, which only a sheet formatted across all of them declares. */+const EXCEL_COLUMN_COUNT = 16384;+/*** Whether a cell holds something the grid has to reach, which is what it is bounded by. A formula* counts even when its result is blank, since the cell is part of the sheet's data, and so does a