Data Operations

GPAL.Excel: Spreadsheet Operations

GPAL.Excel opens a workbook and addresses it the same way a person would -- by sheet, range, cell, row, or column -- for reading values, writing them, running quick calculations, and comparing one range of data against another.

Opening a Workbook and Sheet

GPAL.ExcelFor(file) is shorthand for GPAL.Excel.WithFile(file). Both return a chain where WithSheet(index) or WithSheet(name) selects the active sheet for everything that follows. Close(saveOnClose) closes the workbook, optionally saving changes; SaveTo(file), SaveTo(sheetIndex), and SaveTo(sheetName) write the current state out without necessarily closing.

var excel = GPAL.ExcelFor("report.xlsx")

.WithSheet("Summary");

// ...read or write cells, ranges, etc...

excel.Close(saveOnClose: true);

Addressing Cells, Ranges, Rows, and Columns

You scope operations by selecting a range, a single cell, an entire column, or an entire row. Once the scope is set, write or clear its contents, or modify a cell's existing value by replacing, prepending, or appending text with a configurable separator. The selection narrows or widens between operations without needing to rebuild the Excel object.

var excel = GPAL.ExcelFor("report.xlsx").WithSheet(0);

// Overwrite a single cell

excel.WithCell("B2").SetValue("Revised");

// Append to existing text with a separator

excel.WithCell("C2")

.WithInsertSeparator("; ")

.AppendValue("reviewed");

// Clear a range before writing new data into it

excel.WithRange("A2:D2").ClearRanges();

Calculations and Comparisons

Quick calculations like sum and count run against whatever scope is currently selected and return the result as a string. The comparison feature checks the current selection cell-by-cell against another data source -- a grid, a file, or another range -- and returns the differences as a grid you can save, convert, or email as a discrepancy report.

var excel = GPAL.ExcelFor("budget.xlsx").WithSheet("FY2026");

string total;

excel.WithColumn("D").CalculateSum(out total);

// Compare this month's sheet against last month's exported grid

IGPALGrid<string> differences;

excel.WithRange("A1:D50")

.CompareToGrid(lastMonthGrid)

.GetCompareResults(out differences);

differences.SaveTo("discrepancies.csv");

WARNING

The underlying workbook file stays open (and may be locked) until Close(saveOnClose) is called. If a workflow needs to read the same file with another GPAL subsystem afterward -- GPALConverter or GPAL.FileFor for a copy/move, for example -- call Close first.