GPAL - Generally Positive Automation Library v1.0
GPAL The Fluent Automation LIbrary
Loading...
Searching...
No Matches
GenerallyPositive.GPALExcel Class Reference

Provides fluent, file-based automation of Excel workbooks: opening one or more workbooks (including wildcard-matched sets of files), selecting a sheet, reading/writing ranges, columns, rows and individual cells, performing simple aggregate calculations (sum/count), comparing ranges against a grid, another file, or another range, and saving results back to a file, grid, or sheet. All operations apply to every workbook currently loaded via WithFile(GPALFile), so a single chain can drive many files at once. Errors are reported via GPAL.PublishSimpleEvent rather than thrown. More...

Inheritance diagram for GenerallyPositive.GPALExcel:
GenerallyPositive.IGPALExcel GenerallyPositive.IAllowExcelFileSelection GenerallyPositive.IAllowExcelSheetSelection GenerallyPositive.IAllowExcelOperations GenerallyPositive.IAllowExcelCellSettings GenerallyPositive.IAllowExcelSearchAndReplaceSettings GenerallyPositive.IAllowExcelCompareSettings GenerallyPositive.IAllowToGPALObject< TResult > GenerallyPositive.IAllowExcelCore GenerallyPositive.IAllowExcelCore GenerallyPositive.IAllowToGPALObject< TResult > GenerallyPositive.IAllowExcelSheetSelection GenerallyPositive.IAllowExcelCompareSettings GenerallyPositive.IAllowExcelCore GenerallyPositive.IAllowExcelCore GenerallyPositive.IAllowToGPALObject< TResult >

Public Member Functions

IGPALExcel ToGPALObject ()
 Returns this instance as an IGPALExcel, completing the fluent configuration chain.
IAllowExcelSheetSelection WithFile (GPALFile gpalFile)
 Resets this instance and loads the workbook(s) matching gpalFile 's filenames (which may include wildcard patterns), opening each matched file with ClosedXML. Replaces any previously loaded workbooks, range data, and comparison results.
IAllowExcelOperations WithSheet (int sheetIndex)
 Selects the sheet at the given 1-based index for subsequent Excel operations on every loaded workbook.
IAllowExcelOperations WithSheet (string sheetName)
 Selects the sheet with the given name (case-insensitive) for subsequent Excel operations on every loaded workbook.
IAllowExcelOperations WithRange (string range)
 Reads the given cell range from the currently selected sheet of every loaded workbook and stores the data for use by subsequent operations (e.g. SaveTo(IGPALGrid<string>), WriteRange(string), comparisons). If a previous read/write operation has already been performed on this instance, prior range data and comparison differences are cleared first.
IAllowExcelOperations WriteRange (string range)
 Writes the range data previously read via WithRange(string) (or another data-producing operation) to range on the currently selected sheet of every loaded workbook.
IAllowExcelOperations ClearRanges ()
 Clears any range data read via WithRange(string), WithColumn(string), or WithRowNumber(int), along with any comparison differences accumulated by the CompareTo* methods.
IAllowExcelCellSettings WithCell (string cell)
 Selects a single cell address (e.g. "B3") on the currently selected sheet as the target for subsequent cell operations such as SetValue(string), InsertValue(string), AppendValue(string), and PrependValue(string).
IAllowExcelSearchAndReplaceSettings WithSearchValue (string value)
 Sets the value to search for in subsequent ReplaceWith(string) operations.
IAllowExcelOperations WithColumn (string column)
 Reads every value in the given column from the currently selected sheet of the first loaded workbook that has the selected sheet, storing the result (one value per row) for use by subsequent operations. If a previous read/write operation has already been performed on this instance, prior range data and comparison differences are cleared first.
IAllowExcelOperations WithRowNumber (int rowNumber)
 Reads every value in the given row from the currently selected sheet of the first loaded workbook that has the selected sheet, storing the result (a single row of values) for use by subsequent operations. If a previous read/write operation has already been performed on this instance, prior range data and comparison differences are cleared first.
IAllowExcelOperations CalculateSum (out string result)
 Sums every numeric value across all previously read range data (non-numeric values are ignored).
IAllowExcelOperations CalculateCount (out string result)
 Counts every non-empty value across all previously read range data.
IAllowExcelOperations CompareToGrid (IGPALGrid< string > grid)
 Compares each previously read range against grid , recording any cell-level differences for retrieval via GetCompareResults(out IGPALGrid<string>).
IAllowExcelOperations CompareToFile (GPALFile gpalFile)
 Compares each previously read range against the same range/sheet in the workbook(s) matching gpalFile 's filenames (which may include wildcard patterns), recording any cell-level differences for retrieval via GetCompareResults(out IGPALGrid<string>).
IAllowExcelOperations CompareToRange (string range)
 Compares each previously read range against range on the currently selected sheet of every loaded workbook, recording any cell-level differences for retrieval via GetCompareResults(out IGPALGrid<string>).
IAllowExcelOperations GetCompareResults (out IGPALGrid< string > results)
 Returns the cell-level differences accumulated by the CompareTo* methods (CompareToGrid(IGPALGrid<string>), CompareToFile(GPALFile), CompareToRange(string)) as a grid with columns: File, Sheet, Cell, SourceRange, TargetRange, OldValue, NewValue.
IAllowExcelCellSettings WithInsertPosition (int position)
 Sets where InsertValue(string) places its value relative to the current cell content: 0 inserts before the existing content, any other value inserts after.
IAllowExcelCellSettings WithInsertSeparator (string separator)
 Sets the separator that InsertValue(string) places between the inserted value and the cell's existing content. Defaults to a single space.
IAllowExcelOperations InsertValue (string value)
 Inserts value into the cell selected via WithCell(string) on every loaded workbook, combined with the cell's existing content using the separator from WithInsertSeparator(string) and positioned according to WithInsertPosition(int). Requires WithCell(string), WithInsertPosition(int), and WithInsertSeparator(string) to have been called first.
IAllowExcelOperations SetValue (string value)
 Sets the value of the cell selected via WithCell(string) on every loaded workbook, replacing any existing content.
IAllowExcelOperations AppendValue (string value)
 Appends value to the end of the existing content of the cell selected via WithCell(string) on every loaded workbook.
IAllowExcelOperations PrependValue (string value)
 Prepends value to the beginning of the existing content of the cell selected via WithCell(string) on every loaded workbook.
IAllowExcelOperations ReplaceWith (string value)
 Replaces every occurrence of the value set via WithSearchValue(string) with value , within each previously read range, on the currently selected sheet of every loaded workbook.
IAllowExcelOperations SaveTo (GPALFile gpalFile)
 Saves the loaded workbook(s) to the file(s) matching gpalFile 's filenames (which may include wildcard patterns), or to _gpalFile if gpalFile is null. A workbook whose source path is among the resolved targets is saved in place; otherwise its sheets are copied into a new workbook saved at each resolved target path.
IAllowExcelOperations SaveTo (IGPALGrid< string > grid)
 Appends every row from the previously read range data into grid .
IAllowExcelOperations SaveTo (string sheetName)
 Writes the previously read range data into the sheet named sheetName of every loaded workbook, creating the sheet if it does not exist. If a cell was selected via WithCell(string), only the first value of the last read range is written to that cell; otherwise the full data is written starting at the last read range's address.
IAllowExcelOperations SaveTo (int sheetIndex)
 Writes the previously read range data into the sheet at the given 1-based index of every loaded workbook, creating the sheet (named "Sheet{sheetIndex}") if it does not exist. If a cell was selected via WithCell(string), only the first value of the last read range is written to that cell; otherwise the full data is written starting at the last read range's address.
void Close (bool saveOnClose)
 Closes every loaded workbook, optionally saving each back to its source path first, and clears all cached state. A subsequent operation on this instance will reload the workbooks via ReopenIfClosed. If this instance is already closed, this is a no-op.

Detailed Description

Provides fluent, file-based automation of Excel workbooks: opening one or more workbooks (including wildcard-matched sets of files), selecting a sheet, reading/writing ranges, columns, rows and individual cells, performing simple aggregate calculations (sum/count), comparing ranges against a grid, another file, or another range, and saving results back to a file, grid, or sheet. All operations apply to every workbook currently loaded via WithFile(GPALFile), so a single chain can drive many files at once. Errors are reported via GPAL.PublishSimpleEvent rather than thrown.

GPAL.Excel
.WithFile(GPAL.File.WithFileName("data.xlsx"))
.WithSheet("Sheet1")
.WithRange("A1:B10")
.SaveTo(myGrid);
Everything starts here, all the GPAL controls and global settings using fluent syntax are here....
Definition GPAL.cs:49
static IAllowFileName File
Instantiates a new fluent File SETTINGS object. This data object defines settings for use by the ....
Definition GPAL.cs:508

Definition at line 45 of file GPALExcel.cs.

Member Function Documentation

◆ AppendValue()

IAllowExcelOperations GenerallyPositive.GPALExcel.AppendValue ( string value)

Appends value to the end of the existing content of the cell selected via WithCell(string) on every loaded workbook.

Parameters
valueThe value to append.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCellSettings.

Definition at line 1210 of file GPALExcel.cs.

◆ CalculateCount()

IAllowExcelOperations GenerallyPositive.GPALExcel.CalculateCount ( out string result)

Counts every non-empty value across all previously read range data.

Parameters
resultThe count as a string, or "0" if no range data is available or the count fails.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 657 of file GPALExcel.cs.

◆ CalculateSum()

IAllowExcelOperations GenerallyPositive.GPALExcel.CalculateSum ( out string result)

Sums every numeric value across all previously read range data (non-numeric values are ignored).

Parameters
resultThe sum as a string, or "0" if no range data is available or the sum fails.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 615 of file GPALExcel.cs.

◆ ClearRanges()

IAllowExcelOperations GenerallyPositive.GPALExcel.ClearRanges ( )

Clears any range data read via WithRange(string), WithColumn(string), or WithRowNumber(int), along with any comparison differences accumulated by the CompareTo* methods.

Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 420 of file GPALExcel.cs.

◆ Close()

void GenerallyPositive.GPALExcel.Close ( bool saveOnClose)

Closes every loaded workbook, optionally saving each back to its source path first, and clears all cached state. A subsequent operation on this instance will reload the workbooks via ReopenIfClosed. If this instance is already closed, this is a no-op.

Parameters
saveOnClosetrue to save each workbook to its original path before closing; otherwise false.

Implements GenerallyPositive.IAllowExcelCore.

Definition at line 1696 of file GPALExcel.cs.

◆ CompareToFile()

IAllowExcelOperations GenerallyPositive.GPALExcel.CompareToFile ( GPALFile gpalFile)

Compares each previously read range against the same range/sheet in the workbook(s) matching gpalFile 's filenames (which may include wildcard patterns), recording any cell-level differences for retrieval via GetCompareResults(out IGPALGrid<string>).

Parameters
gpalFileThe file (or wildcard pattern) identifying the workbook(s) to compare against.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCompareSettings.

Definition at line 777 of file GPALExcel.cs.

◆ CompareToGrid()

IAllowExcelOperations GenerallyPositive.GPALExcel.CompareToGrid ( IGPALGrid< string > grid)

Compares each previously read range against grid , recording any cell-level differences for retrieval via GetCompareResults(out IGPALGrid<string>).

Parameters
gridThe grid to compare each read range against.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCompareSettings.

Definition at line 699 of file GPALExcel.cs.

◆ CompareToRange()

IAllowExcelOperations GenerallyPositive.GPALExcel.CompareToRange ( string range)

Compares each previously read range against range on the currently selected sheet of every loaded workbook, recording any cell-level differences for retrieval via GetCompareResults(out IGPALGrid<string>).

Parameters
rangeThe cell range to compare each previously read range against (e.g. "A1:B10").
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCompareSettings.

Definition at line 908 of file GPALExcel.cs.

◆ GetCompareResults()

IAllowExcelOperations GenerallyPositive.GPALExcel.GetCompareResults ( out IGPALGrid< string > results)

Returns the cell-level differences accumulated by the CompareTo* methods (CompareToGrid(IGPALGrid<string>), CompareToFile(GPALFile), CompareToRange(string)) as a grid with columns: File, Sheet, Cell, SourceRange, TargetRange, OldValue, NewValue.

Parameters
resultsThe comparison results, with a header row even if no differences were found.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 1004 of file GPALExcel.cs.

◆ InsertValue()

IAllowExcelOperations GenerallyPositive.GPALExcel.InsertValue ( string value)

Inserts value into the cell selected via WithCell(string) on every loaded workbook, combined with the cell's existing content using the separator from WithInsertSeparator(string) and positioned according to WithInsertPosition(int). Requires WithCell(string), WithInsertPosition(int), and WithInsertSeparator(string) to have been called first.

Parameters
valueThe value to insert.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCellSettings.

Definition at line 1098 of file GPALExcel.cs.

◆ PrependValue()

IAllowExcelOperations GenerallyPositive.GPALExcel.PrependValue ( string value)

Prepends value to the beginning of the existing content of the cell selected via WithCell(string) on every loaded workbook.

Parameters
valueThe value to prepend.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCellSettings.

Definition at line 1266 of file GPALExcel.cs.

◆ ReplaceWith()

IAllowExcelOperations GenerallyPositive.GPALExcel.ReplaceWith ( string value)

Replaces every occurrence of the value set via WithSearchValue(string) with value , within each previously read range, on the currently selected sheet of every loaded workbook.

Parameters
valueThe replacement value.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelSearchAndReplaceSettings.

Definition at line 1322 of file GPALExcel.cs.

◆ SaveTo() [1/4]

IAllowExcelOperations GenerallyPositive.GPALExcel.SaveTo ( GPALFile gpalFile)

Saves the loaded workbook(s) to the file(s) matching gpalFile 's filenames (which may include wildcard patterns), or to _gpalFile if gpalFile is null. A workbook whose source path is among the resolved targets is saved in place; otherwise its sheets are copied into a new workbook saved at each resolved target path.

Parameters
gpalFileThe file (or wildcard pattern) identifying where to save, or null to save back to the originally loaded file(s).
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCore.

Definition at line 1386 of file GPALExcel.cs.

◆ SaveTo() [2/4]

IAllowExcelOperations GenerallyPositive.GPALExcel.SaveTo ( IGPALGrid< string > grid)

Appends every row from the previously read range data into grid .

Parameters
gridThe grid to append the read range data to.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCore.

Definition at line 1484 of file GPALExcel.cs.

◆ SaveTo() [3/4]

IAllowExcelOperations GenerallyPositive.GPALExcel.SaveTo ( int sheetIndex)

Writes the previously read range data into the sheet at the given 1-based index of every loaded workbook, creating the sheet (named "Sheet{sheetIndex}") if it does not exist. If a cell was selected via WithCell(string), only the first value of the last read range is written to that cell; otherwise the full data is written starting at the last read range's address.

Parameters
sheetIndexThe 1-based index of the destination sheet.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCore.

Definition at line 1624 of file GPALExcel.cs.

◆ SaveTo() [4/4]

IAllowExcelOperations GenerallyPositive.GPALExcel.SaveTo ( string sheetName)

Writes the previously read range data into the sheet named sheetName of every loaded workbook, creating the sheet if it does not exist. If a cell was selected via WithCell(string), only the first value of the last read range is written to that cell; otherwise the full data is written starting at the last read range's address.

Parameters
sheetNameThe name of the destination sheet.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCore.

Definition at line 1548 of file GPALExcel.cs.

◆ SetValue()

IAllowExcelOperations GenerallyPositive.GPALExcel.SetValue ( string value)

Sets the value of the cell selected via WithCell(string) on every loaded workbook, replacing any existing content.

Parameters
valueThe value to set.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelCellSettings.

Definition at line 1156 of file GPALExcel.cs.

◆ ToGPALObject()

IGPALExcel GenerallyPositive.GPALExcel.ToGPALObject ( )

Returns this instance as an IGPALExcel, completing the fluent configuration chain.

Implements GenerallyPositive.IAllowToGPALObject< TResult >.

Definition at line 141 of file GPALExcel.cs.

◆ WithCell()

IAllowExcelCellSettings GenerallyPositive.GPALExcel.WithCell ( string cell)

Selects a single cell address (e.g. "B3") on the currently selected sheet as the target for subsequent cell operations such as SetValue(string), InsertValue(string), AppendValue(string), and PrependValue(string).

Parameters
cellThe cell address to target.
Returns
Fluent interface to define cell-related settings or perform Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 440 of file GPALExcel.cs.

◆ WithColumn()

IAllowExcelOperations GenerallyPositive.GPALExcel.WithColumn ( string column)

Reads every value in the given column from the currently selected sheet of the first loaded workbook that has the selected sheet, storing the result (one value per row) for use by subsequent operations. If a previous read/write operation has already been performed on this instance, prior range data and comparison differences are cleared first.

Parameters
columnThe column letter(s) to read (e.g. "A").
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 492 of file GPALExcel.cs.

◆ WithFile()

IAllowExcelSheetSelection GenerallyPositive.GPALExcel.WithFile ( GPALFile gpalFile)

Resets this instance and loads the workbook(s) matching gpalFile 's filenames (which may include wildcard patterns), opening each matched file with ClosedXML. Replaces any previously loaded workbooks, range data, and comparison results.

Parameters
gpalFileThe file (or wildcard pattern) identifying the workbook(s) to load.
Returns
Fluent interface to select a sheet for further Excel operations.

Implements GenerallyPositive.IAllowExcelFileSelection.

Definition at line 150 of file GPALExcel.cs.

◆ WithInsertPosition()

IAllowExcelCellSettings GenerallyPositive.GPALExcel.WithInsertPosition ( int position)

Sets where InsertValue(string) places its value relative to the current cell content: 0 inserts before the existing content, any other value inserts after.

Parameters
positionThe insert position (0 = before existing content, otherwise after).
Returns
Fluent interface to define cell-related settings or perform Excel operations.

Implements GenerallyPositive.IAllowExcelCellSettings.

Definition at line 1047 of file GPALExcel.cs.

◆ WithInsertSeparator()

IAllowExcelCellSettings GenerallyPositive.GPALExcel.WithInsertSeparator ( string separator)

Sets the separator that InsertValue(string) places between the inserted value and the cell's existing content. Defaults to a single space.

Parameters
separatorThe separator string to use.
Returns
Fluent interface to define cell-related settings or perform Excel operations.

Implements GenerallyPositive.IAllowExcelCellSettings.

Definition at line 1071 of file GPALExcel.cs.

◆ WithRange()

IAllowExcelOperations GenerallyPositive.GPALExcel.WithRange ( string range)

Reads the given cell range from the currently selected sheet of every loaded workbook and stores the data for use by subsequent operations (e.g. SaveTo(IGPALGrid<string>), WriteRange(string), comparisons). If a previous read/write operation has already been performed on this instance, prior range data and comparison differences are cleared first.

Parameters
rangeThe cell range to read (e.g. "A1:B10").
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 296 of file GPALExcel.cs.

◆ WithRowNumber()

IAllowExcelOperations GenerallyPositive.GPALExcel.WithRowNumber ( int rowNumber)

Reads every value in the given row from the currently selected sheet of the first loaded workbook that has the selected sheet, storing the result (a single row of values) for use by subsequent operations. If a previous read/write operation has already been performed on this instance, prior range data and comparison differences are cleared first.

Parameters
rowNumberThe 1-based row number to read.
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 554 of file GPALExcel.cs.

◆ WithSearchValue()

IAllowExcelSearchAndReplaceSettings GenerallyPositive.GPALExcel.WithSearchValue ( string value)

Sets the value to search for in subsequent ReplaceWith(string) operations.

Parameters
valueThe value to search for.
Returns
Fluent interface to define search-and-replace settings or perform Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 466 of file GPALExcel.cs.

◆ WithSheet() [1/2]

IAllowExcelOperations GenerallyPositive.GPALExcel.WithSheet ( int sheetIndex)

Selects the sheet at the given 1-based index for subsequent Excel operations on every loaded workbook.

Parameters
sheetIndexThe 1-based index of the sheet to select.
Returns
Fluent interface to perform Excel operations on the selected sheet.

Implements GenerallyPositive.IAllowExcelSheetSelection.

Definition at line 209 of file GPALExcel.cs.

◆ WithSheet() [2/2]

IAllowExcelOperations GenerallyPositive.GPALExcel.WithSheet ( string sheetName)

Selects the sheet with the given name (case-insensitive) for subsequent Excel operations on every loaded workbook.

Parameters
sheetNameThe name of the sheet to select.
Returns
Fluent interface to perform Excel operations on the selected sheet.

Implements GenerallyPositive.IAllowExcelSheetSelection.

Definition at line 251 of file GPALExcel.cs.

◆ WriteRange()

IAllowExcelOperations GenerallyPositive.GPALExcel.WriteRange ( string range)

Writes the range data previously read via WithRange(string) (or another data-producing operation) to range on the currently selected sheet of every loaded workbook.

Parameters
rangeThe destination cell range to write to (e.g. "A1:B10").
Returns
Fluent interface to perform further Excel operations.

Implements GenerallyPositive.IAllowExcelOperations.

Definition at line 356 of file GPALExcel.cs.


The documentation for this class was generated from the following file: