Skip to content

Commit d514047

Browse files
only lookup cells once per row
1 parent 84684ae commit d514047

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Public/Import-Excel.ps1

+10-3
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,15 @@
217217
#Disabled write-verbose for speed
218218
# Write-Verbose "Import row '$R'"
219219
$NewRow = [Ordered]@{ }
220+
221+
# Get the entire row
222+
$rowCells = $sheet.Cells[$R, $StartColumn, $R, $EndColumn].Value
223+
224+
$i = 0
225+
220226
if ($TextColRegEx) {
221227
foreach ($P in $PropertyNames) {
222-
$cell = $sheet.Cells[$R, $P.Column]
228+
$cell = $rowCells[0, $i]
223229
$MatchTest = $TextColRegEx.Match($P.value)
224230
if ($MatchTest.groups.name -eq "astext") {
225231
$NewRow[$P.Value] = $cell.Text
@@ -228,12 +234,13 @@
228234
$NewRow[$P.Value] = [datetime]::FromOADate($cell.Value)
229235
}
230236
else { $NewRow[$P.Value] = $cell.Value }
237+
$i++
231238
}
232239
}
233240
else {
234241
foreach ($P in $PropertyNames) {
235-
$NewRow[$P.Value] = $sheet.Cells[$R, $P.Column].Value
236-
# Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'."
242+
$NewRow[$P.Value] = $rowCells[0, $i]
243+
$i++
237244
}
238245
}
239246
$xlBook["$targetSheetname"] += [PSCustomObject]$NewRow

0 commit comments

Comments
 (0)