From 5ed6d423bbd56b1462a3194be680540d92513028 Mon Sep 17 00:00:00 2001 From: Inference_ <68734681+Inference1@users.noreply.github.com> Date: Wed, 22 Jul 2026 00:40:15 +0800 Subject: [PATCH] Fix rotated text overriding custom row heights --- .../Handlers/Excel/ExcelHandler.HtmlPreview.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/officecli/Handlers/Excel/ExcelHandler.HtmlPreview.cs b/src/officecli/Handlers/Excel/ExcelHandler.HtmlPreview.cs index cb72559ea..21ba7b138 100644 --- a/src/officecli/Handlers/Excel/ExcelHandler.HtmlPreview.cs +++ b/src/officecli/Handlers/Excel/ExcelHandler.HtmlPreview.cs @@ -492,12 +492,16 @@ private void RenderSheetTable(StringBuilder sb, string sheetName, WorksheetPart // Row height and hidden row lookup var rowHeights = new Dictionary(); + var customHeightRows = new HashSet(); var hiddenRows = new HashSet(); foreach (var row in rows) { var rowIdx = (int)(row.RowIndex?.Value ?? 0); if (row.CustomHeight?.Value == true && row.Height?.Value != null) + { rowHeights[rowIdx] = row.Height.Value; + customHeightRows.Add(rowIdx); + } // A row with height 0 is a hidden row in real Excel (mirrors the // hidden-column treatment, which drops width<=0 columns). Emit it // display:none rather than as a ~16px gap. The original row numbers @@ -507,14 +511,15 @@ private void RenderSheetTable(StringBuilder sb, string sheetName, WorksheetPart hiddenRows.Add(rowIdx); } - // Rotated-text rows auto-grow in real Excel so the vertical string is - // visible. The HTML only carries transform:rotate, which keeps the - // glyph box at its un-rotated width — the row stays at default height and - // clips. Bump the row's min-height to the rotated text extent (approx - // text-length × font-size for ~90°), consistent with the spill/width - // estimation heuristics elsewhere in this renderer. + // Rotated-text rows with automatic height grow in real Excel so the + // vertical string is visible. The HTML only carries transform:rotate, + // which keeps the glyph box at its un-rotated width — the row stays at + // default height and clips. Bump the row's min-height to the rotated text + // extent (approx text-length × font-size for ~90°), but never override an + // OOXML customHeight row: that height is an explicit user constraint. foreach (var ((r, _), cell) in cellMap) { + if (customHeightRows.Contains(r)) continue; var extent = EstimateRotatedCellHeightPt(cell, stylesheet, renderStyles, defaultFontPt); if (extent <= 0) continue; if (!rowHeights.TryGetValue(r, out var existing) || existing < extent)