# 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
# 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}
# 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',' # return the changed object $_ } | Export-Excel-Path$path-ClearSheet-WorksheetName$sheetName-Show
# any object-oriented data will do # we create some sample records via CSV # to mimick specific issues $rawData = @' Data,Name Test, Tobias =), Mary =:-(), Tom '@ | ConvertFrom-Csv
# 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}
# any object-oriented data will do # we create some sample records via CSV # to mimick specific issues $rawData = @' Data,Name Test, Tobias =), Mary =:-(), Tom '@ | ConvertFrom-Csv
# 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}
#region Post-process the column with the misinterpreted formulas # remove the region to repro the original Excel error $sheet1 = $excel.Workbook.Worksheets[$sheetName]
# take all cells from row "A"... $sheet1.Cells['A:A'] | # ...that are currently interpreted as a formula... Where-Object Formula | ForEach-Object { # ...construct the original content which is the formula # plus a prepended "=" $newtext = ('={0}'-f$_.Formula) # reformat cell to number type "TEXT" Set-Format-Address$_-NumberFormat'Text'-Value'dummy' # assign the original content to the cell (this cannot be done using Set-Format) $_.Value = $newtext } #endregion
# any object-oriented data will do # we create some sample records via CSV # to mimick specific issues $rawData = @' Phone,Name +4915125262524, Tobias 0766256725672, Mary 00496253168722567, Tom '@ | ConvertFrom-Csv
# 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}
# any object-oriented data will do # we create some sample records via CSV # to mimick specific issues $rawData = @' Phone,Name +4915125262524, Tobias 0766256725672, Mary 00496253168722567, Tom '@ | ConvertFrom-Csv
# 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}