-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Can't export Array to Excel with LoadFromArrays from Powershell #37
Comments
@ili101 Interesting. This might also be a good addition to the ImportExcel module for loading large datasets. |
@ili101 Well, I don't have knowledge about PowerShell, but in C# the type expected is |
The problem is that the Get-Process function returns an array of object arrays, not an IEnumerable<Object[]>
You can force the Array<Object[]> into IEnumerable<Object[]> as follows:
You can also use > $null at the end of the line instead of $null = at the beginning of the line, and it makes the code a bit clearer |
@blairdaviesbc Thank you for the explanation. $process = [Collections.Generic.List[Object[]]]::new()
$PsProcess = Get-ChildItem
$Process.Add($PsProcess[0].PsObject.Properties.Name)
$PsProcess | ForEach-Object { $Process.Add($_.PsObject.Properties.Value) }
$null = $ws.Cells['A1'].LoadFromArrays($Process) But now I see that we can use LoadFromCollection for that by only converting the array to a list like this: $process = [Collections.Generic.List[System.IO.FileSystemInfo]]::new()
$TestObject = Get-ChildItem
foreach ($item in $TestObject)
{
$Process.Add($item)
}
$BindingFlags = [Reflection.BindingFlags] 'NonPublic, Static'
$MemberInfo = [System.IO.FileSystemInfo].GetMembers().Where({$_.Name -in 'Name','LastWriteTime'})
[OfficeOpenXml.Table.TableStyles]$TableStyle = 'Medium6'
$null = $ws.Cells['A1'].LoadFromCollection($process,$true,$TableStyle,$BindingFlags,$MemberInfo) |
This seems to be solved, so I'll close it |
Hi
I'm not sure if this is a bug, future request or I just using the wrong syntax.
I asked at the forums and we did not manage to make it work.
I need to export large amount of data to Excel with PowerShell.
First I used this great module https://github.com/dfinke/ImportExcel that works but is to slow for my data as It's writing the data with EPPlus.dll cell by cell so it's slow.
The dll also has methods to load an array of objects or a DataTable at once which is much faster, I can get the DataTable method to work but I can't figure out how to load an array with "LoadFromArrays"
Example:
Thank you
The text was updated successfully, but these errors were encountered: