WeTi
asked on
PS change color in html rapport
Dear experts
Please help with scripting below:
$Arr variable got a table created.
Batchname TimeStamp BatchEndedOK FileMissing
--------- --------- ------------ -----------
H60 2020-01-27 13:00:55 True True
H52 2020-01-27 09:39:00 True False
T60 2020-01-27 09:00:22 True False
We could like to show this in HTML code like:
if BatchEndOk -eq false
<tr bgcolor=red>.............. ....<td bgcolor=red></td>
if FileMissing -eq false and BatchEndOk -eq true
<tr bgcolor=green>............ ......<td bgcolor=red></td>
Else
<tr bgcolor=green>............ ......<td bgcolor=green></td>
Two challenges, 1. the HTML, script need to create a HTML structured tables and show the result in it.
2. how to change the HTML code foreach line?
Thanks
Please help with scripting below:
$Arr variable got a table created.
$Arr | Select-Object -Property BatchName, TimeStamp, BatchEndedOK, FileMissing | ForEach-Object {
if (FileMissing -eq true) {
$a = $a + "<style>"
$a = $a + "BODY{background-color:white;font-family:verdana;font-size:12px;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px;background-color:#0dfc2d}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px}"
$a = $a + "tr:nth-child(odd) { background-color:#d3d3d3;}"
$a = $a + "tr:nth-child(even) { background-color:white;}"
$a = $a + "</style>"
$htmlout = $sqlArr | Select "BatchName", "TimeStamp", "BatchEndedOK", "FileMissing" | convertto-html -head $a
}
else {
$htmlout = $sqlArr | Select "BatchName", "TimeStamp", "BatchEndedOK", "FileMissing" | convertto-html -head $a
}
}
$Arr looks like this:Batchname TimeStamp BatchEndedOK FileMissing
--------- --------- ------------ -----------
H60 2020-01-27 13:00:55 True True
H52 2020-01-27 09:39:00 True False
T60 2020-01-27 09:00:22 True False
We could like to show this in HTML code like:
if BatchEndOk -eq false
<tr bgcolor=red>..............
if FileMissing -eq false and BatchEndOk -eq true
<tr bgcolor=green>............
Else
<tr bgcolor=green>............
Two challenges, 1. the HTML, script need to create a HTML structured tables and show the result in it.
2. how to change the HTML code foreach line?
Thanks
ASKER
No its wrong, Correction:
$htmlout | ForEach-Object {
If ($sqlArr.batchEndedOK -match 'True' -and $sqlArr.FileMissing -match 'False') {
}
If ($sqlArr.batchEndedOK -match 'False') {
}
if ($sqlArr.batchEndedOK -match 'True' -and $sqlArr.FileMissing -match 'True') {
}
}
ASKER
Progress:
I can match the htmlout variable row with this param:
I can match the htmlout variable row with this param:
$htmlout | ForEach-Object {
If ($htmlout -match '</td><td>True</td><td>False</td>') {
$test01++
}
If ($htmlout-match '</td><td>False</td><td>False</td>') {
$test02++
}
if ($htmlout-match '</td><td>True</td><td>True</td>') {
$test03++
}
}
$test01
$test02
$test03
Now i can replace the text string with color string i think...
ASKER
Progress:
$htmlout | ForEach-Object {
If ($htmlout -match '</td><td>True</td><td>False</td>') {
$htmlout-replace ("<tr>","<tr bgcolor=green>" )#-and "</td><td>True</td><td>True</td>", "<td>red</td>")
}
If ($htmlout-match '</td><td>False</td><td>False</td>') {
$htmlout-replace ("<tr>", "<tr bgcolor=red>")
}
if ($htmlout-match '</td><td>True</td><td>True</td>') {
$htmlout-replace ("<tr>","<tr bgcolor=green>" )#-and "</td><td>True</td><td>True</td>", "<td>green</td>")
}
}
$htmlout
This code replace the whole htmlout to <tr bgcolor=green>...
ASKER
Progress:
$sqlArr | Select-Object -Property BatchName, TimeStamp, BatchEndedOK, FileMissing
$a = $a + "<style>"
$a = $a + "BODY{background-color:white;font-family:verdana;font-size:12px;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px;background-color:#0dfc2d}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px}"
$a = $a + "tr:nth-child(odd) { background-color:#d3d3d3;}"
$a = $a + "tr:nth-child(even) { background-color:white;}"
$a = $a + "</style>"
$htmlout = $sqlArr | Select "BatchName", "TimeStamp", "BatchEndedOK", "FileMissing" | convertto-html #-head $a
foreach ($line in $htmlout){
#$htmlout | ForEach-Object {
If ($line -match '</td><td>True</td><td>False</td>') {
$result = $result + $line-replace ("<tr>","<tr bgcolor=green>")
$result = $result + $line-replace ("</td><td>True</td><td>True</td>", "<td>red</td>")
}
If ($line -match '</td><td>False</td><td>False</td>') {
$result = $result + $line-replace ("<tr>", "<tr bgcolor=red>")
}
if ($line -match '</td><td>True</td><td>True</td>'){
$result = $result + $line-replace ("<tr>","<tr bgcolor=green>")
$result = $result + $line-replace ("</td><td>True</td><td>True</td>", "<td>green</td>")
}
$line
}
$result
Still not working
ASKER
$htmlout = $sqlArr | Select "BatchName", "TimeStamp", "BatchEndedOK", "FileMissing" | convertto-html
$htmlout | ForEach-Object {
if ($_ -match "</td><td>True</td><td>True</td>"){
$count++
$htmlout -replace ("<tr>","<tr bgcolor=green>")
}
If ($_ -match '</td><td>True</td><td>False</td>') {
$count2++
}
If ($_ -match '</td><td>false</td><td>False</td>') {
$count3++
}
}
$count
$count2
$count3
$htmlout
This is for debug. I need to see if the if statements works, and the $count 2 3 works. I stuck with if the statement is true, replace the current line to $htmlout, right now it replace everything....
Check my version:
$a = $a + "<style>`r`n"
$a = $a + "BODY{background-color:white;font-family:verdana;font-size:12px;}`r`n"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}`r`n"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px;background-color:#0dfc2d}`r`n"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px}`r`n"
$a = $a + "tr.filemissing {background-color:orangered!important;}`r`n"
$a = $a + "tr.filenotmissing {background-color:lightgreen!important;}`r`n"
$a = $a + "</style>`r`n"
$a = $a + "<script>`r`n"
$a = $a + "window.onload=function(){`r`n"
$a = $a + " var intColFileMissing = 3;`r`n"
$a = $a + " var rows = document.getElementsByTagName('table')[0].rows;`r`n"
$a = $a + " for(var i=1;i<rows.length;i++){`r`n"
$a = $a + " if(rows[i].cells[intColFileMissing].innerHTML.replace(/\s/g,'')!='False'){`r`n"
$a = $a + " rows[i].className = 'filenotmissing';`r`n"
$a = $a + " }else{`r`n"
$a = $a + " rows[i].className = 'filemissing';`r`n"
$a = $a + " }`r`n"
$a = $a + " }`r`n"
$a = $a + "}`r`n"
$a = $a + "</script>`r`n"
$htmlout = $sqlArr | Select "BatchName", "TimeStamp", "BatchEndedOK", "FileMissing" | convertto-html -head $a
Out-File -FilePath zvonko.html -InputObject $htmlout -Encoding UTF8
Hello WeTi,
you have to click the link "Open in new window" to see my code.
...and I just noticed that I have assigned in the style section the colers wrong.
Change the green and red rows coloring.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for answer odBA and ZVonko, I will try when I feel better from the flu. Return to you guys later. Thanks again
Good convalescence : )
ASKER
After sickness now I feels better, oBdA is still doing the magic, great thanks to him and also Zvonko.
You are welcome : )
ASKER
Open in new window
I think I am abit processing the code. $htmlout need to change out the lines with the criteria above.