0

I need a bit of help from any of the coders out there.....

Currently, the code Reads which a CSV file and then outputs it to a html file using Powershell. And I have to use Powershell as there are other bits to this code(not shown here) which uses Powershell.

How do you colour a row on a table depending on a value of a cell?

Current bit of code look as below.


$datagridView1.DataSource | Export-Csv c:\tmp\test.csv

#HTML OUTPUT   

$head= @"
<style>
BODY{background-color:white;}
TABLE{border-width: 3px;border-style: solid; border-color:white;border-collapse:
collapse;}
TH{border-width: 3px;padding: 2px;border-style: solid;border-color: white;background-     color:yellow}


</style>

<script type="text/javascript">
    var allText =[];
    var allTextLines = [];
    var Lines = [];

    var txtFile = new XMLHttpRequest();
    txtFile.open("GET", "file://c:/tmp/test.csv", true);
    txtFile.onreadystatechange = function()
    {
        allText = txtFile.responseText;
        allTextLines = allText.split(/\r\n|\n/);
    };

    document.write(allTextLines);<br>
    document.write(allText);<br>
    document.write(txtFile);<br>
</script>
"@
$datagridView1.DataSource | convertto-html -head $head –body "<H2>Query</H2>" | Out-File         C:\tmp\app.html

The app.html file also seems to be creating the following four columns which are not in the CSV file (RowError, RowState, Table, ItemArray, HasErrors) and I can't figure out where its coming from.

Any help would be greatly appreciated

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
cruzer
  • 5
  • 2
  • We can't see your table here or the condition needed to color it, but basically `if (theCell.innerHTML == 'the condition') {theCell.parentNode.style.backgroundColor = '#FF0000';}` – Michael Berkowski Jun 22 '12 at 02:36
  • Possible duplicate of [Change colour of table cells depending on value](http://stackoverflow.com/questions/18992382/change-colour-of-table-cells-depending-on-value) – Pavel Gatnar Apr 08 '16 at 13:18

1 Answers1

0

The following would make any table background a color of blue if the table data has a value of 3:

$("td:contains('3')").css({'background-color':'blue'});

jQuery is an amazing tool for simplifying your code. Though JavaScript is great for understanding basic programing principles along with object oriented syntax. jQuery sticks to its motto of write less, do more.

For more information visit this site.

moribvndvs
  • 42,191
  • 11
  • 135
  • 149