0

I have a list of items and I'm displaying their field values in Show-ListView.

Some fields are multilist fields, so I'm fetching those item names and including them as individual lines within single cells.

For example:

New lines in table cells

Here's the code I'm using to display those individual multi list fields:

@{Label ="Services";Expression={
  (($_["services"].Split("|") | ForEach-Object { 
    (Get-Item -Path master: -ID $_).Name + "<br/>" + [Environment]::NewLine
  }))
}}

Note that I had to append a <br/> and [Environment]::NewLine to each line value to get it to show up nicely in the table. The table displays as HTML, so the <br/>, or some other HTML + CSS is necessary to give it this appearance. The [Environment]::NewLine is included for when the table data gets exported as an Excel file.

Once I'm in the Excel file, I:

  • Select all
  • Set all cells to wrap text so that the new lines show
  • Find and replace all <br/> tags with an empty string

Is there a way I can override the export functionality to automatically remove the <br/> to remove this manual step?

It seems one option might be to call something like this after displaying the table:

Import-Function -Name ConvertTo-Xlsx

[byte[]]$outobject = $AllItemsAsCustomPSObjects | ConvertTo-Xlsx 

Out-Download -Name "report.xlsx" -InputObject $outobject

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.