From cfb556ea7737a9f8a0a7d9331fb633745641cc72 Mon Sep 17 00:00:00 2001 From: Edward Miller Date: Sun, 19 May 2024 21:50:25 -0500 Subject: [PATCH] only lookup cells once per row --- Public/Import-Excel.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Public/Import-Excel.ps1 b/Public/Import-Excel.ps1 index 920ce1c..44657aa 100644 --- a/Public/Import-Excel.ps1 +++ b/Public/Import-Excel.ps1 @@ -217,9 +217,13 @@ #Disabled write-verbose for speed # Write-Verbose "Import row '$R'" $NewRow = [Ordered]@{ } + + # Get the entire row first + $row = $sheet.Cells[$R, 1, $R, $sheet.Dimension.End.Column] + if ($TextColRegEx) { foreach ($P in $PropertyNames) { - $cell = $sheet.Cells[$R, $P.Column] + $cell = $row[$R, $P.Column] $MatchTest = $TextColRegEx.Match($P.value) if ($MatchTest.groups.name -eq "astext") { $NewRow[$P.Value] = $cell.Text @@ -232,7 +236,7 @@ } else { foreach ($P in $PropertyNames) { - $NewRow[$P.Value] = $sheet.Cells[$R, $P.Column].Value + $NewRow[$P.Value] = $row[$R, $P.Column].Value # Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'." } }