Skip to content

feat: add SheetStats with GetSheetStats and CalculateSheetStats (E1)#2327

Open
AdamDrewsTR wants to merge 2 commits into
qax-os:masterfrom
AdamDrewsTR:feat/sheet-stats
Open

feat: add SheetStats with GetSheetStats and CalculateSheetStats (E1)#2327
AdamDrewsTR wants to merge 2 commits into
qax-os:masterfrom
AdamDrewsTR:feat/sheet-stats

Conversation

@AdamDrewsTR
Copy link
Copy Markdown
Contributor

Summary

Add SheetStats struct and methods to compute and cache worksheet data extent statistics.

SheetStats Struct

type SheetStats struct {
    Rows    int    // Total number of rows with data
    Cols    int    // Maximum column index used
    Cells   int64  // Total number of non-empty cells
    MaxCell string // Cell reference of the bottom-right used cell (e.g., "Z100")
}

Methods

  • CalculateSheetStats(sheet string) (*SheetStats, error) — Iterates all rows/columns using the Rows iterator, computes statistics, and caches the result. Subsequent calls return the cached value.
  • GetSheetStats(sheet string) *SheetStats — Returns previously cached stats without recalculating, or nil if not yet computed.

Usage

f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
    return err
}
defer f.Close()

stats, err := f.CalculateSheetStats("Sheet1")
if err != nil {
    return err
}
fmt.Printf("Rows: %d, Cols: %d, Cells: %d, MaxCell: %s\n",
    stats.Rows, stats.Cols, stats.Cells, stats.MaxCell)

// Later retrieval without recalculation:
cached := f.GetSheetStats("Sheet1")

Add SheetStats struct containing computed worksheet statistics:
- Rows: total number of rows with data
- Cols: maximum column index used
- Cells: total number of non-empty cells
- MaxCell: cell reference of the bottom-right used cell

CalculateSheetStats iterates all rows/columns in a sheet using the
Rows iterator, computes the statistics, and caches the result in the
File struct. Subsequent calls return the cached value.

GetSheetStats returns previously cached stats without recalculating.
@AdamDrewsTR AdamDrewsTR changed the title feat: add SheetStats with GetSheetStats and CalculateSheetStats feat: add SheetStats with GetSheetStats and CalculateSheetStats (E1) May 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.60%. Comparing base (4bebb61) to head (115c266).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2327   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files          32       32           
  Lines       26791    26824   +33     
=======================================
+ Hits        26685    26718   +33     
  Misses         55       55           
  Partials       51       51           
Flag Coverage Δ
unittests 99.60% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xuri xuri added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 13, 2026
Add comprehensive tests for GetSheetStats and CalculateSheetStats
covering normal operation, caching, empty sheets, non-existent sheets,
and Columns() error paths. Remove unreachable rows.Error() check
since Rows.err is never set in the standard implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants