Skip to content

Build your personal knowledge base with Trilium Notes

client/spreadsheet/print & PDF export: vertical align content by default to the bottom of the cell

Adorian Doranba3740261619
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 5027e3bbe2..85e00cefbc 100644
--- a/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts
+++ b/packages/commons/src/lib/spreadsheet/render_to_html.spec.ts
@@ -766,8 +766,19 @@ describe("renderSpreadsheetToHtml", () => {
it("omits vertical-align for an unknown vertical alignment", () => {
const html = renderSpreadsheetToHtml(singleCellWorkbook({ v: "x", s: { vt: 9 } }));
- expect(html).not.toContain("vertical-align");
+ // The cell contributes none, so it falls back to the row's.
expect(html).toContain("<td>x</td>");
+ expect(html).toContain(`<tr style="height:24px;vertical-align:bottom">`);
+ });
+
+ it("defaults a row to the bottom, which a cell's own alignment overrides", () => {
+ // Univer leaves a cell at the bottom of its row unless it sets `vt`, unlike HTML.
+ const html = renderSpreadsheetToHtml(singleCellWorkbook({ v: "x" }));
+ expect(html).toContain(`<tr style="height:24px;vertical-align:bottom">`);
+ expect(html).toContain("<td>x</td>");
+
+ const middle = renderSpreadsheetToHtml(singleCellWorkbook({ v: "x", s: { vt: 2 } }));
+ expect(middle).toContain(`<td style="vertical-align:middle">x</td>`);
});
it("renders borders on all four sides with the correct Univer widths and styles", () => {
@@ -973,7 +984,7 @@ describe("renderSpreadsheetToHtml", () => {
});
const html = renderSpreadsheetToHtml(input);
expect(html).toContain('<col style="width:200px">');
- expect(html).toContain('<tr style="height:50px">');
+ expect(html).toContain('<tr style="height:50px;vertical-align:bottom">');
});
it("falls back to default column width and row height when absent", () => {
@@ -999,7 +1010,7 @@ describe("renderSpreadsheetToHtml", () => {
});
const html = renderSpreadsheetToHtml(input);
expect(html).toContain('<col style="width:88px">');
- expect(html).toContain('<tr style="height:24px">');
+ expect(html).toContain('<tr style="height:24px;vertical-align:bottom">');
});
it("renders an empty string for a cell with null value", () => {
diff --git a/packages/commons/src/lib/spreadsheet/render_to_html.ts b/packages/commons/src/lib/spreadsheet/render_to_html.ts
index 9f9766f302..c68be50bb9 100644
--- a/packages/commons/src/lib/spreadsheet/render_to_html.ts
+++ b/packages/commons/src/lib/spreadsheet/render_to_html.ts
@@ -281,7 +281,10 @@ function renderSheet(sheet: IWorksheetData, styles: Record<string, IStyleData |
if (rowMeta?.hd) continue;
const height = isFiniteNumber(rowMeta?.h) ? rowMeta.h : defaultHeight;
- lines.push(`<tr style="height:${height}px">`);
+ // Univer leaves a cell at the bottom of its row unless it sets `vt`, while HTML centres it.
+ // The row carries that default because a `td` inherits `vertical-align`, so a cell that
+ // sets its own still wins.
+ lines.push(`<tr style="height:${height}px;vertical-align:bottom">`);
for (let col = minCol; col <= maxCol; col++) {
if (columnData[col]?.hd) continue;