Another approach: I convert the listview to xml then I can add css classes and finally export as html:
# HTML formatting
$head = @"
<style>
BODY{background-color:white;}
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: LightBlue}
TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: white}
.status1{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status1.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status3{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status3.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status8{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status8.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status9{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status9.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status81{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status81.gif');background-repeat:no-repeat;background-size:80px 18px;}
.status91{width:80px;height:18px;background-image: url('C:/Programdata/ZPTInfo/Icons/status91.gif');background-repeat:no-repeat;background-size:80px 18px;}
</style>
"@
$filedate=Get-Date -UFormat '%m-%d-%Y-%H%M%S'
$filename = "C:\Temp\export_" + $filedate + ".htm"
#$filename = "C:\Temp\export_.htm"
# Convert the selection to an XML object
[xml]$xmlObject = $WPFergebnisse.items | select-Object Ebene,Typ,Pos,Identnr,BENr,Bez,AGKurz,Menge,Status,letzterm,einkaufskz,zusatz | ConvertTo-Html -Fragment
# Parse XML object and set colour class according to value in 4th last column
for($i=1;$i -le $xmlObject.table.tr.count-1;$i++) {
switch($xmlObject.table.tr[$i].td[-4] -as [int]){
1 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status1') }
3 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status3') }
8 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status8') }
9 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status9') }
81 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status81') }
91 { $xmlObject.table.tr[$i].ChildNodes[($xmlObject.table.tr[$i].ChildNodes.Count-4)].SetAttribute('class','status91') }
}
}
# Define body and append the modified XML object
$body = @"
<H5>Generiert am: $filedate</H5>
$($xmlObject.innerxml)
"@
# Convert to HTML and save the file
ConvertTo-Html -Head $head -Body $body | Out-File $filename