Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Public/Import-Excel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
}

$targetSheetname = $sheet.Name
$xlBook["$targetSheetname"] = @()
$xlBook["$targetSheetname"] = [System.Collections.Generic.List[object]]::new()
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider preallocating the list capacity if the expected number of rows can be estimated to further optimize performance and reduce potential reallocations.

Suggested change
$xlBook["$targetSheetname"] = [System.Collections.Generic.List[object]]::new()
$rowCount = $sheet.Dimension.End.Row - $StartRow + 1
$xlBook["$targetSheetname"] = [System.Collections.Generic.List[object]]::new($rowCount)

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@scriptingstudio scriptingstudio May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good suggestion. Never thought of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made some tests using preallocating. no difference

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought, back in the Visual Basic days, before classes. When you did a ReDim on an already allocated array, we found that it was better to allocate 50% more than the size of the array as you went. Size 10, use it the ReDim to 15 not 11. Then 22, 33 and so on. Very effective.

No clue if that can play here.

#region Get rows and columns
#If we are doing dataonly it is quicker to work out which rows to ignore before processing the cells.
if (-not $EndRow ) { $EndRow = $sheet.Dimension.End.Row }
Expand Down Expand Up @@ -235,7 +235,7 @@
# Write-Verbose "Import cell '$($Worksheet.Cells[$R, $P.Column].Address)' with property name '$($p.Value)' and value '$($Worksheet.Cells[$R, $P.Column].Value)'."
}
}
$xlBook["$targetSheetname"] += [PSCustomObject]$NewRow
$xlBook["$targetSheetname"].Add([PSCustomObject]$NewRow)
}
#endregion
}
Expand Down