Write to an Existing Excel File¶
Enumerate the Excel File¶
The cmdlets Open-ExcelPackage
and Close-ExcelPackage
allow for direct modification to Excel file contents.
Enumerate the Worksheet to View or Modify the Data¶
$WorkSheet = $ExcelPkg.Workbook.Worksheets["sheet1"].Cells #open excel worksheet cells from worksheet "sheet1"
A1 contains "someHeader", A2 contains "data1" etc.
Modify a Specific Value in a File¶
Values can be accessed by row, column. Similar to a 2D array.
Contents of file.xlsx after modifying:Load Value at Specific Index¶
$ValueAtIndex
now contains:
Save File After Modifying¶
The changes will not display in the Excel file until Close-ExcelPackage is called.