Skip to content

Build your personal knowledge base with Trilium Notes

client/spreadsheet: improve the loading performance

Adorian Doran9c1f4ae3a63c
diff --git a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts b/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts
index cb62be1e5a..c4eb302bbe 100644
--- a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts
+++ b/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts
@@ -1980,9 +1980,9 @@ describe("renderSpreadsheetToHtml", () => {
urlDrawing("img1", "api/attachments/cgN4jEBCA1Kn/image/image.png", { left: 0, top: 0, width: 200, height: 10 })
])
);
- // Default 88px columns: the image right edge at 200px reaches column 2, so 3 columns emit.
- const colCount = (html.match(/<col /g) ?? []).length;
- expect(colCount).toBe(3);
+ // Default 88px columns: the image right edge at 200px reaches column 2, so 3 columns emit,
+ // as one `col` spanning them since they share a width.
+ expect(html).toContain(`<col span="3" style="width:88px">`);
});
it("does not shrink the grid when a floating image fits within the data bounds", () => {
@@ -2214,8 +2214,8 @@ describe("renderSpreadsheetToHtml", () => {
it("renders leading empty columns so the grid starts at the sheet origin", () => {
// Data only at column 2 -> columns 0 and 1 must still be emitted.
const html = renderSpreadsheetToHtml(cellAtWorkbook(0, 2));
- const colCount = (html.match(/<col /g) ?? []).length;
- expect(colCount).toBe(3);
+ // Three columns of the same width, so one `col` spans them.
+ expect(html).toContain(`<col span="3" style="width:88px">`);
});
it("extends bounds to cover a merge range that exceeds the cell data", () => {
diff --git a/packages/commons/src/lib/spreadsheet/render_to_html.ts b/packages/commons/src/lib/spreadsheet/render_to_html.ts
index 051fe9ad84..b940eb6b1f 100644
--- a/packages/commons/src/lib/spreadsheet/render_to_html.ts
+++ b/packages/commons/src/lib/spreadsheet/render_to_html.ts
@@ -325,8 +325,11 @@ function renderSheet(sheet: IWorksheetData, styles: Record<string, IStyleData |
lines.push(buildTableTag(sheet, totalWidth));
lines.push("<colgroup>");
- for (const width of colWidths) {
- lines.push(`<col style="width:${px(width)}px">`);
+ for (let index = 0; index < colWidths.length;) {
+ let span = 1;
+ while (index + span < colWidths.length && colWidths[index + span] === colWidths[index]) span++;
+ lines.push(`<col${span > 1 ? ` span="${span}"` : ""} style="width:${px(colWidths[index])}px">`);
+ index += span;
}
lines.push("</colgroup>");