From e9b437af4e20b5542911140e629e321967b1b899 Mon Sep 17 00:00:00 2001 From: Davis Henckel <51898571+DavisHenckel@users.noreply.github.com> Date: Fri, 26 Nov 2021 06:56:08 -0800 Subject: [PATCH] Complete first version of ExistingExcelFile FAQ Added loading a row/col, then mapping to HashTable --- FAQ/How to Read an Existing Excel File.md | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/FAQ/How to Read an Existing Excel File.md b/FAQ/How to Read an Existing Excel File.md index 2bf246c..7a633e8 100644 --- a/FAQ/How to Read an Existing Excel File.md +++ b/FAQ/How to Read an Existing Excel File.md @@ -12,3 +12,29 @@ The File C:\Test\file.xlsx contains After Loading this data into ```$ExcelFile``` the data is stored like: ![ExcelFileDebugImg](/images/FAQ_Images/ExcelFileDebugImg.jpg) + +## Other Common Operations + +### Load a Column +```powershell +$SpecificColumn = $ExcelFile."anotherHeader" #loads column with the header "another header" store into an array +``` + +### Load a Row +```powershell +$SpecificRow = $ExcelFile[1] #Loads row at index 1. Index 1 is the first row instead of 0. +``` + +### Map Contents to HashTable to interpret data +Sometimes mapping to a HashTable is more convenient to have access to common Hashtable operations. Enumerate a HashTable with the Row data properties by: +```powershell +$HashTable = @{} +$SpecificRow= $ExcelFile[2] +$SpecificRow.psobject.properties | ForEach-Object {$HashTable[$_.Name] = $_.Value} +``` +To then iterate through the enumerated hash... +```powershell +ForEach ($Key in ($HashTable.GetEnumerator()) | Where-Object {$_.Value -eq "x"}){ #Only grabs a key where the value is "x" + #values accessible with $Key.Name or $Key.Value +} +```