Allow setting row height without the customHeight attribute
Feature request
I would like a way to write a row height (ht) without setting the customHeight attribute.
How this differs from existing issues
I am aware of #92, #204, #1209, #1351, #2028 and #2044, which ask the library to compute the row height (AutoFit). I understand that requires measuring the actual font metrics and is a large amount of work.
This request is different: I compute the height myself. All I need is control over one attribute in the generated XML.
What is not possible today
There are two public ways to set a row height, and both always set customHeight:
SetRowHeightsetsCustomHeight = true(rows.go:453)StreamWriter.SetRowwritescustomHeight="1"whenHeight > 0(stream.go:359)
The only way to get CustomHeight = false is SetRowHeight(sheet, row, -1), but that also sets Ht = nil, so the height value itself is dropped (rows.go:447-450).
The internal xlsxRow.CustomHeight field has omitempty (xmlWorksheet.go:318), so a row with ht and no customHeight is representable — it is just not reachable from the public API.
Why this matters
When customHeight is set, Excel treats the height as user-defined and does not recalculate it. Without the attribute, Excel recalculates the height from the cell contents when the file is opened.
We generate report spreadsheets and would like both of the following:
- Accurate heights when opened in Excel — so we do not want
customHeight - Rows that do not collapse in viewers that never auto-fit (Google Sheets, various preview tools) — so we do want to keep an estimated
ht
There is currently no way to do this. Our workaround is to write the file, reopen the resulting ZIP, and strip the customHeight attribute from the sheet XML with a regular expression. That depends on the exact output format of the library and breaks quietly if it changes.
Possible API
Either shape would work:
Option 1 — an option parameter on SetRowHeight:
func (f *File) SetRowHeight(sheet string, row int, height float64, opts ...RowHeightOptions) errorOption 2 — an options struct with CustomHeight *bool, which would also line up with RowOpts used by StreamWriter.
Environment
excelize v2.11.0
Source: qax-os/excelize