From d71dd36d56268319df13efe4a24819d4984a79dd Mon Sep 17 00:00:00 2001 From: Davis Henckel <51898571+DavisHenckel@users.noreply.github.com> Date: Fri, 26 Nov 2021 12:17:39 -0800 Subject: [PATCH 1/4] First version of file, with Image. --- FAQ/How to Write to an Existing Excel File.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/FAQ/How to Write to an Existing Excel File.md b/FAQ/How to Write to an Existing Excel File.md index e69de29..15120e0 100644 --- a/FAQ/How to Write to an Existing Excel File.md +++ b/FAQ/How to Write to an Existing Excel File.md @@ -0,0 +1,19 @@ +# Write to an Existing Excel File +### Enumerate the Excel File +```powershell +$ExcelPkgFile = Open-ExcelPackage -Path "C:\Test\file.xlsx" +``` +Contents of file.xlsx: +![ExcelFileContents](/images/FAQ_Images/ExcelFileContents.png) +### Enumerate the Worksheet to View or Modify the Data +```powershell +$WorkSheet = $ExcelPkgFile.Workbook.Worksheets["sheet1"].Cells #open excel worksheet cells from worksheet "sheet1" +``` +Visual of Data Structure: +![DataStructureExcelPkg](/images/FAQ_Images/DataStructureExcelPkg.png) + +Modify a specific value by accessing row/col like a 2D Array: +```powershell +$WorkSheet[1,4].Value = "New Column Header" #Starts at index 1 not 0 +``` + From 6ebac7b6dc525ae6f77e22bf1c6cf917cdbb13f3 Mon Sep 17 00:00:00 2001 From: Davis Henckel <51898571+DavisHenckel@users.noreply.github.com> Date: Fri, 26 Nov 2021 12:18:05 -0800 Subject: [PATCH 2/4] Add newlines --- FAQ/How to Write to an Existing Excel File.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FAQ/How to Write to an Existing Excel File.md b/FAQ/How to Write to an Existing Excel File.md index 15120e0..e8f6361 100644 --- a/FAQ/How to Write to an Existing Excel File.md +++ b/FAQ/How to Write to an Existing Excel File.md @@ -3,13 +3,13 @@ ```powershell $ExcelPkgFile = Open-ExcelPackage -Path "C:\Test\file.xlsx" ``` -Contents of file.xlsx: +Contents of file.xlsx: ![ExcelFileContents](/images/FAQ_Images/ExcelFileContents.png) ### Enumerate the Worksheet to View or Modify the Data ```powershell $WorkSheet = $ExcelPkgFile.Workbook.Worksheets["sheet1"].Cells #open excel worksheet cells from worksheet "sheet1" ``` -Visual of Data Structure: +Visual of Data Structure: ![DataStructureExcelPkg](/images/FAQ_Images/DataStructureExcelPkg.png) Modify a specific value by accessing row/col like a 2D Array: From 4d6193f5494d99f7a166f64e220619672db6f5c4 Mon Sep 17 00:00:00 2001 From: Davis Henckel <51898571+DavisHenckel@users.noreply.github.com> Date: Fri, 26 Nov 2021 14:28:04 -0800 Subject: [PATCH 3/4] Complete Majority of Write to ExistingExcelFile md --- FAQ/How to Write to an Existing Excel File.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/FAQ/How to Write to an Existing Excel File.md b/FAQ/How to Write to an Existing Excel File.md index e8f6361..e4e5fcc 100644 --- a/FAQ/How to Write to an Existing Excel File.md +++ b/FAQ/How to Write to an Existing Excel File.md @@ -16,4 +16,16 @@ Modify a specific value by accessing row/col like a 2D Array: ```powershell $WorkSheet[1,4].Value = "New Column Header" #Starts at index 1 not 0 ``` +Contents of file.xlsx after modifying: +![ExcelFileContentsPostAdd](/images/FAQ_Images/ExcelFileContentsPostAdd.png) +Can also load a value at a specific index: +```powershell +$ValueAtIndex = $WorkSheet[2,1].Value #Loads the value at row 2, column A +``` +### Save File After Modifying +The changes will not display in the Excel file until Close-ExcelPackage is called. +```powershell +Close-ExcelPackage $ExcelPkgFile #close and save changes made to the Excel file. +``` +**Note**: If the file is currently in use, Close-ExcelPackage will return an error and will not save the information. From 86a7865fb2ffb1fa9f8a5db43409e90c8d324e4a Mon Sep 17 00:00:00 2001 From: Davis Henckel <51898571+DavisHenckel@users.noreply.github.com> Date: Fri, 26 Nov 2021 14:34:17 -0800 Subject: [PATCH 4/4] Add multiple images. --- FAQ/How to Write to an Existing Excel File.md | 1 + 1 file changed, 1 insertion(+) diff --git a/FAQ/How to Write to an Existing Excel File.md b/FAQ/How to Write to an Existing Excel File.md index e4e5fcc..9a9839a 100644 --- a/FAQ/How to Write to an Existing Excel File.md +++ b/FAQ/How to Write to an Existing Excel File.md @@ -22,6 +22,7 @@ Can also load a value at a specific index: ```powershell $ValueAtIndex = $WorkSheet[2,1].Value #Loads the value at row 2, column A ``` +```$ValueAtIndex``` now contains: ![ValueAtIndexData](/images/FAQ_Images/ValueAtIndexData.png) ### Save File After Modifying The changes will not display in the Excel file until Close-ExcelPackage is called. ```powershell