Description
Add a method to count non-empty (non-blank, non-whitespace) cells in a sheet without requiring the caller to iterate all rows in their language.
Use case
When processing large workbooks (75k+ cells per sheet), we need the populated cell count to decide between processing paths. Currently we must:
- Call
GetRows()
- Iterate every cell in the caller's language (Python).
- Check
cell != "" && strings.TrimSpace(cell) != ""
- Count
This is wasteful because:
- The Go library already has access to the parsed XML data internally
- Crossing the CGo boundary for every cell is expensive for bindings (excelize-py)
- The caller often just needs the count, not the actual cell values
Proposed API
// GetPopulatedCellCount returns the number of non-empty cells in a worksheet.
// A cell is considered populated if its value is not empty and not whitespace-only.
func (f *File) GetPopulatedCellCount(sheet string) (int, error)
Why this should live in excelize
- The data is already parsed internally - counting in Go avoids re-iteration
- For CGo/FFI bindings (excelize-py, excelize-wasm), this eliminates thousands of boundary crossings per sheet
- Common need for analytics, validation, and threshold-based processing decisions
- Trivial to implement — single pass over internal cell data
Description
Add a method to count non-empty (non-blank, non-whitespace) cells in a sheet without requiring the caller to iterate all rows in their language.
Use case
When processing large workbooks (75k+ cells per sheet), we need the populated cell count to decide between processing paths. Currently we must:
GetRows()cell != "" && strings.TrimSpace(cell) != ""This is wasteful because:
Proposed API
Why this should live in excelize