Skip to content

Commit

Permalink
only lookup cells once per row
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardmiller-mesirow committed May 20, 2024
1 parent 84684ae commit d514047
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Public/Import-Excel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,15 @@
#Disabled write-verbose for speed
# Write-Verbose "Import row '$R'"
$NewRow = [Ordered]@{ }

# Get the entire row
$rowCells = $sheet.Cells[$R, $StartColumn, $R, $EndColumn].Value

$i = 0

if ($TextColRegEx) {
foreach ($P in $PropertyNames) {
$cell = $sheet.Cells[$R, $P.Column]
$cell = $rowCells[0, $i]
$MatchTest = $TextColRegEx.Match($P.value)
if ($MatchTest.groups.name -eq "astext") {
$NewRow[$P.Value] = $cell.Text
Expand All @@ -228,12 +234,13 @@
$NewRow[$P.Value] = [datetime]::FromOADate($cell.Value)
}
else { $NewRow[$P.Value] = $cell.Value }
$i++
}
}
else {
foreach ($P in $PropertyNames) {
$NewRow[$P.Value] = $sheet.Cells[$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)'."
$NewRow[$P.Value] = $rowCells[0, $i]
$i++
}
}
$xlBook["$targetSheetname"] += [PSCustomObject]$NewRow
Expand Down

0 comments on commit d514047

Please sign in to comment.