Excel

Opening and Navigating Excel Files

WithFile sets the Excel file to work with using a GPALFile reference. WithSheet selects the target worksheet by name (string) or by number (integer), counting from 1, which is the sheet a workbook opens on. Close closes the workbook - pass true to save changes before closing. ToGPALObject returns the IGPALExcel interface for storage or injection. All subsequent operations (read, write, compare) apply to the sheet selected with WithSheet.

NOTE

SaveTo(GPALFile) writes the workbook to a file. SaveTo(string) writes the range that was read into a sheet of that name, creating it when it is not there. A bare path string is a string, so it makes a sheet named after the path rather than a file.

Examples

GPAL Fluent: High-level fluent C# API

//WithSheet takes a sheet name or a sheet number counting from 1. Name a sheet before reading or writing: there is no default, and an operation with no sheet selected reports an invalid sheet. SaveTo takes a GPALFile to write a file and a string to write a sheet, so cast a path when you mean a file.

// Open a workbook and select a sheet by name

GPAL.Excel

.WithFile("report.xlsx")

.WithSheet("Sales Data")

.WithRange("A1:D50")

.SaveTo((GPALFile)"extracted.csv");


// Open, modify, and close with save

GPAL.Excel

.WithFile("data.xlsx")

.WithSheet(1) // the sheet the workbook opens on

.WithCell("B2")

.SetValue("Updated")

.Close(true);

💬 Ask GPAL