Excel

Reading and Exporting Data

SaveTo with a GPALFile writes the targeted range to a file (CSV, XLSX, etc. based on extension). SaveTo with an IGPALGrid<string> populates an in-memory grid with the range data. SaveTo with a sheet name or index copies the data to another sheet. CalculateSum computes the sum of numeric values in the range. CalculateCount counts the non-empty cells. Both calculation methods return their result as an out string parameter.

Examples

GPAL Fluent: High-level fluent C# API

//SaveTo(IGPALGrid<string>) returns the data with each row corresponding to an Excel row and each column to an Excel column within the targeted range.

// Read a range into a grid

var grid = GPAL.Grid.ToGPALObject();

GPAL.Excel

.WithFile("sales.xlsx")

.WithSheet("Q4")

.WithRange("A1:D200")

.SaveTo(grid);


// Get the sum of a range

string total;

GPAL.Excel

.WithFile("sales.xlsx")

.WithSheet("Q4")

.WithRange("D2:D200")

.CalculateSum(out total);


// Export to a CSV file

GPAL.Excel

.WithFile("data.xlsx")

.WithSheet("Export")

.WithRange("A1:Z500")

.SaveTo("export.csv");

💬 Ask GPAL