Description
Add an option to GetRows and Rows (streaming iterator) that expands merged cell values — filling all cells in a merged range with the anchor cell's value instead of returning empty strings for non-anchor cells.
Use case
When reading a sheet with merged cells, the current behavior returns the value only in the top-left (anchor) cell of the merged range. All other cells in the range return empty strings. To get the "visual" representation of the spreadsheet (what a user sees), callers must:
- Call
GetRows(sheet)
- Call
GetMergeCells(sheet)
- Parse each range string (e.g., "A1:C3") into coordinates
- Expand: for each cell in each merged range, fill with anchor value
- Merge the expanded values back into the row data
This is ~30 lines of boilerplate that every caller doing data extraction needs. Addimidedly, this is mostly useful right now for parsing excel files as mardkown (i.e. to pass it to an LLM)
Proposed API
type Options struct {
// ... existing fields ...
// ExpandMergedCells fills all cells in a merged range with the anchor cell's value.
// Default: false (current behavior preserved).
ExpandMergedCells bool
}
Usage:
rows, err := f.GetRows("Sheet1", excelize.Options{ExpandMergedCells: true})
// Now merged ranges have the anchor value in every cell, not just the top-left
Current workaround
// Pseudocode of what every caller does today:
rows, _ := f.GetRows(sheet)
merged, _ := f.GetMergeCells(sheet)
for _, mc := range merged {
startAxis := mc.GetStartAxis()
endAxis := mc.GetEndAxis()
value := mc.GetCellValue()
// Parse axes into row/col coordinates
// Fill all cells in range with value
}
Why this should live in excelize
- The merge metadata is already loaded during file parsing
- Expanding during row iteration avoids a second pass over the merge list
- Every data extraction use case needs the "visual" representation, not the raw storage representation
- The
Options struct already exists for controlling row reading behavior — this fits naturally
Description
Add an option to
GetRowsandRows(streaming iterator) that expands merged cell values — filling all cells in a merged range with the anchor cell's value instead of returning empty strings for non-anchor cells.Use case
When reading a sheet with merged cells, the current behavior returns the value only in the top-left (anchor) cell of the merged range. All other cells in the range return empty strings. To get the "visual" representation of the spreadsheet (what a user sees), callers must:
GetRows(sheet)GetMergeCells(sheet)This is ~30 lines of boilerplate that every caller doing data extraction needs. Addimidedly, this is mostly useful right now for parsing excel files as mardkown (i.e. to pass it to an LLM)
Proposed API
Usage:
Current workaround
Why this should live in excelize
Optionsstruct already exists for controlling row reading behavior — this fits naturally