# get some raw data that contains arrays $rawData = Get-EventLog-LogName System -Newest10 | Select-Object-Property TimeWritten, ReplacementStrings, InstanceId
# create this Excel file $Path = "$env:temp\report.xlsx" # make sure the file is deleted so we have no # effects from previous data still present in the # file. This requires that the file is not still # open and locked in Excel $exists = Test-Path-Path$Path if ($exists) { Remove-Item-Path$Path}
$sheetName = 'Testdata' $rawData | ForEach-Object { # convert column "ReplacementStrings" from array to string $_.ReplacementStrings = $_.ReplacementStrings -join"`r`n" # return the changed object $_ } | Export-Excel-Path$path-ClearSheet-WorksheetName$sheetName-Show
# get some raw data that contains arrays $rawData = Get-EventLog-LogName System -Newest10 | Select-Object-Property TimeWritten, ReplacementStrings, InstanceId
# create this Excel file $Path = "$env:temp\report.xlsx" # make sure the file is deleted so we have no # effects from previous data still present in the # file. This requires that the file is not still # open and locked in Excel $exists = Test-Path-Path$Path if ($exists) { Remove-Item-Path$Path}
$sheetName = 'Testdata'
# save the Excel object model by using -PassThru instead of -Show $excel = $rawData | ForEach-Object { # convert column "ReplacementStrings" from array to string $_.ReplacementStrings = $_.ReplacementStrings -join"`r`n" # return the changed object $_ } | Export-Excel-Path$path-ClearSheet-WorksheetName$sheetName-AutoSize-PassThru
#region Post-process the column with the misinterpreted formulas # remove the region to repro the original Excel error $sheet1 = $excel.Workbook.Worksheets[$sheetName] # reformat cell to number type "TEXT" with WordWrap and AutoSize Set-Format-Address$sheet1.Cells['B:B'] -NumberFormat'Text'-WrapText-AutoSize #endregion