diff --git a/Public/Import-Excel.ps1 b/Public/Import-Excel.ps1 index 920ce1c9..812422fb 100644 --- a/Public/Import-Excel.ps1 +++ b/Public/Import-Excel.ps1 @@ -217,25 +217,33 @@ #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] + $cellValue = $rowCells[0, $i] $MatchTest = $TextColRegEx.Match($P.value) if ($MatchTest.groups.name -eq "astext") { - $NewRow[$P.Value] = $cell.Text + $NewRow[$P.Value] = $cellValue } - elseif ($MatchTest.groups.name -eq "asdate" -and $cell.Value -is [System.ValueType]) { - $NewRow[$P.Value] = [datetime]::FromOADate($cell.Value) + elseif ($MatchTest.groups.name -eq "asdate" -and $cellValue -is [System.ValueType]) { + $NewRow[$P.Value] = [datetime]::FromOADate($cellValue) } - else { $NewRow[$P.Value] = $cell.Value } + else { $NewRow[$P.Value] = $cellValue } + $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 } #endregion