Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell - Hash Table Handling not working...

$
0
0

Hi

I am trying to sort an Excel Sheet and getting no where fast.

One issue at a time, i read the headers OK and you can see from the screendump below that the info is in the array.

However when i go to find the index, it returns zero, and a subsequent ContainsKey returns false.

I am looking for "Date Modified" $sortByColumnName

>> What am i doing wrong or is this an encoding issue ? i.e. the powershell "keys" is in a different encoding to the passed string ?

I am stumped..

Thanks

		$headers = Read-Headers $objWorksheet
		[int]$index = $headers[$sortByColumnName]
		# or same result, zero
		[int]$index = $headers.Get_Item($sortByColumnName)
		Write-Host 'Contains key ' $headers.ContainsKey($sortByColumnName)
		# returns false
		 Function Read-Headers {
		# Parameters: Excel worksheet
		# Returns: Hash table of the contents of each cell in the first row and the
		#    corresponding column number
		# Use: $Worksheet.cells.item($Row,$Headers["IP"])
		# Note: Processes until first blank cell
		    Param ($Worksheet)    
		    $Headers =@{}
		    $column = 1
		    Do {
		        $Header = $Worksheet.cells.item(1,$column).text
		        If ($Header) {
		            $Headers.add($Header, $column)
		            $column++
		        }
		    } until (!$Header)
		    return $Headers
		}



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>