IGGt
IGGt

Reputation: 2769

Powershell - Using ConvertTo-HTML and need to add CSS based on a fields content

I am using Powershell's (v2) ConvertTo-HTML function to convert a SQL query to a table that I then include in an email. On a basic level it works fine, but I now want to add some CSS to colour a field if that field is greater than 0.

My SQL is:

$SQL1 = "SELECT DATE, LS, TCO, FCO FROM test.table1 
        WHERE DATE = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
        ORDER BY LS"

Example Data is:

'2015-09-29', 'aaa', 150, 10
'2015-09-29', 'bbb', 267, 0

My Powershell is:

$table1 = $result1 | `
ConvertTo-Html `
    -property DATE, `
        LSR, `
        TCO, `
        FCO `
    -Fragment

 $htmlbody = @"
    <html>
    <head><title>HTML TABLE</title></head>
    <body>
        <style> [CSS GOES HERE] </style>
        . . .
        $table1
    </body>
    </html>
"@           

But I need to be able to add css to the last field on the table so if the field is > 0 I add a class to turn it red. I'm assuming I need some kind of IF statement somewhere

IF [field] > 0 THEN [ADD CLASS]

But can't see where to put it. Is this possible?

Upvotes: 0

Views: 944

Answers (1)

IGGt
IGGt

Reputation: 2769

From What I have been able to deduce, it is not possible to add CSS to individual elements using ConvertTo-Html.

I did however find a function called called ConvertTo-ADVHtml which does allow this.See Here

Upvotes: 0

Related Questions