Data Operations

GPALGrid: Working with Tabular Data

GPALGrid is GPAL's in-memory table. Rows and columns of data that scraped values, file contents, and database results all flow through, with the same indexers and actions regardless of where the data came from or where it's going.

Rows, Columns, and Cells

GPALGrid is GPAL's in-memory table object. You can build one up by adding rows, columns, or individual cells, and address any cell by its row and column index. Standard collection operations like count and contains work the same way they do on any other collection. The grid is a string grid throughout -- that is the type every other GPAL subsystem reads and writes.

var grid = GPAL.Grid.ToGPALObject();

grid.AddColumn(new List<string> { "Id", "Name", "Total" });

grid.AddRow(new List<string> { "1", "Alice", "42.00" });

grid.AddRow(new List<string> { "2", "Bob", "17.50" });

string name = grid[1, 1]; // "Alice"

List<string> row2 = grid[2]; // ["2", "Bob", "17.50"]

int rowCount = grid.Rows;

bool hasBob = grid.Contains("Bob");

The Hub Between Files and Databases

InputFrom and SaveTo/OutputTo make a grid the common middle step between any two data sources: InputFrom(GPALFile) or InputFrom(IGPALDatabase) populate the grid, and SaveTo(GPALFile) or OutputTo(IGPALDatabase) write it back out. Because GPALConverter, GPAL.Excel, and GPALDatabase all read from and write to IGPALGrid<string>, a grid is frequently the object that moves data between those subsystems within a single workflow.

// Load a CSV into a grid, then write the same grid into a database table

var grid = GPAL.Grid.ToGPALObject();

grid.InputFrom("contacts.csv");

var db = GPAL.Database

.WithConnectionString("...")

.WithTableName("Contacts")

.ToGPALObject();

grid.OutputTo(db);

// Or go the other direction - query results into a grid, then to Excel

grid.InputFrom(db);

grid.SaveTo("contacts.xlsx");

Editing, Clearing, and Cloning

DeleteRow(RowPosition.First) or DeleteRow(RowPosition.Last) remove the first or last row -- useful for stripping a header row after InputFrom when WithFirstLineIsColumnNames wasn't set on the source. Clear() empties the grid entirely while keeping the same object reference, which matters when other parts of a workflow already hold that reference. Clone() returns an independent copy -- changes to the clone never affect the original, which is the usual way to keep a 'before' snapshot while transforming a 'working' grid.

var grid = GPAL.Grid.ToGPALObject();

grid.InputFrom("export.csv");

// First row was actually a header - drop it

grid.DeleteRow(RowPosition.First);

// Keep an untouched copy before transforming

var original = (IGPALGrid<string>)grid.Clone();

grid.Clear();

TIP

IGPALGrid<T> is generic, but GPAL.Grid produces IGPALGrid<string>. The type used throughout the rest of GPAL (file input/output, database results, Excel ranges, converter input/output). You won't normally need any other T.