Application

Reading Data

GetGrid reads the current selectors into a GPALGrid, passed by ref so repeated calls can accumulate into one grid. It works two ways depending on what the selectors describe. A single selector resolving to a control that exposes the UIAutomation GridPattern is read structurally, cell by cell, and TablePattern supplies the column headers. Otherwise each selector is a column and its repeating matches are the rows, which is the WithAllThatMatch model. Missing cells carry GPAL.ErrorPlaceholder rather than shifting the row. SaveTo and AppendTo write the grid, with the format and delimiter coming from the GPALFile's extension. WithHeader names a column, and WithGridToSave hands over a grid built elsewhere.

NOTE

Column names come from WithHeader first, then the output file's own columns, then the selector names, then the control's own headers, and anything still unnamed becomes column1, column2 and so on. The list is never shorter than the widest row, because the writer keys each row's cells by column name and a column with no name would be a column with no data. Names are also made unique for the same reason: two columns sharing a name would collapse into one holding the last value, so Size and Size become Size and Size2.

WARNING

A control answers for its text through one of two UIAutomation patterns. TextPattern hands back the whole document. ValuePattern is meant for a short value, an edit field or a combo entry, and the provider behind the control caps what it returns, commonly at 4096 characters. GPAL asks for TextPattern first, so the cap only appears on a control that has no TextPattern at all, and Notepad++ is one of those. Nothing in UIAutomation says a value was cut, so GetGrid comes back with part of a long document and looks complete. Where that happens, select all and copy inside the application and read the clipboard instead. See GetClipboard under Clipboard.

Examples

GPAL Fluent: High-level fluent C# API

//WithAllThatMatch takes the number of rows to keep, defaulting to all of them. A grid read through GridPattern brings its own column headers, and WithHeader after GetGrid replaces that list rather than adding to it, so name every column or name none. GetGrid leaves its result on the unit of work as well as in the grid handed back, which is what a following SaveTo or AppendTo writes.

// a control that offers GridPattern reads structurally

IGPALGrid<string> rows = GPAL.Grid.ToGPALObject();


myApplication

.WithSelector(fileList)

.GetGrid(ref rows)

.SaveTo(@"C: eportslisting.csv");


// one selector per column, repeating matches as rows

myApplication

.WithSelector(nameColumn)

.WithSelector(sizeColumn)

.WithAllThatMatch()

.GetGrid(ref rows)

.WithHeader("Name")

.WithHeader("Size")

.SaveTo(@"C: eportscolumns.csv");

💬 Ask GPAL