Description
Add a method that returns only non-empty cells as structured data (row, column, value), skipping empty cells entirely. This avoids forcing callers to iterate through potentially millions of empty cells just to build a sparse grid.
Use case
When building data extraction pipelines (e.g., converting spreadsheets to structured data for LLM processing), the typical pattern is:
GetRows(sheet)
- Iterate in caller's language, skip empty cells
- Build a sparse map:
(row, col) -> value
For a sheet with dimension A1:Z5000 (130k potential cells) but only 20k populated cells, we're iterating 110k empty cells for nothing. The Go library already knows which cells have values during XML parsing.
Proposed API
type CellInfo struct {
Row int
Col int
Value string
}
// GetNonEmptyCells returns all non-empty cells in a worksheet as a slice of CellInfo.
// Options control formatting behavior (same as GetRows).
func (f *File) GetNonEmptyCells(sheet string, opts ...Options) ([]CellInfo, error)
Or alternatively, a streaming version:
// NonEmptyCells returns an iterator over non-empty cells in a worksheet.
func (f *File) NonEmptyCells(sheet string, opts ...Options) (*CellIterator, error)
Why this should live in excelize
- Go already parses XML and knows which cells have values — filtering in Go avoids crossing CGo boundary for empty cells
- Reduces memory: callers don't need to hold
[][]string with all the empty padding
- Common pattern: every user building sparse representations does this filtering manually
- Complements the existing
Rows streaming iterator for cases where you want sparse access
Description
Add a method that returns only non-empty cells as structured data (row, column, value), skipping empty cells entirely. This avoids forcing callers to iterate through potentially millions of empty cells just to build a sparse grid.
Use case
When building data extraction pipelines (e.g., converting spreadsheets to structured data for LLM processing), the typical pattern is:
GetRows(sheet)(row, col) -> valueFor a sheet with dimension A1:Z5000 (130k potential cells) but only 20k populated cells, we're iterating 110k empty cells for nothing. The Go library already knows which cells have values during XML parsing.
Proposed API
Or alternatively, a streaming version:
Why this should live in excelize
[][]stringwith all the empty paddingRowsstreaming iterator for cases where you want sparse access