#2362·excelize

Feature request: GetPopulatedCellCount(sheet) — count non-empty cells without full iteration in Go

Author: mcschmitzCreated Jul 27, 2026Updated Jul 27, 2026

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:

  1. Call GetRows()
  2. Iterate every cell in the caller's language (Python).
  3. Check cell != "" && strings.TrimSpace(cell) != ""
  4. 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

go
// 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