Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Alternate rows colors

Reply
 
Old 06-10-2008   #1 (permalink)
Jason1008


 
 

Alternate rows colors

This is the beginning of my script

$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 3px;border-style: solid;border-color:
white;border-collapse: collapse;}"
$a = $a + "TH{border-width: 3px;padding: 2px;border-style:
solid;border-color: white;background-color:yellow}"
$a = $a + "TD{border-width: 3px;padding: 2px;border-style:
solid;border-color: white;background-color:lightblue}"
$a = $a + "</style>"

get-eventlog -logname application | select Source, EntryType | group-object
Source | where-object {$_.Group -match "Error"} | select Name, Count | sort
Name | convertto-html -head $a –body "<H2>Application Errors</H2>" | Out-File
f:\app.htm

Invoke-Expression f:\app.htm

I would like to alternate the row color for each data; that is one row is
lightblue, the next white, then the next row is lightblue and the next one
white and it goes on like that.



My System SpecsSystem Spec
Old 06-10-2008   #2 (permalink)
Jeff


 
 

Re: Alternate rows colors

On Jun 10, 2:09 pm, Jason1008 <Jason1...@xxxxxx>
wrote:
Quote:

> This is the beginning of my script
>
> $a = "<style>"
> $a = $a + "BODY{background-color:white;}"
> $a = $a + "TABLE{border-width: 3px;border-style: solid;border-color:
> white;border-collapse: collapse;}"
> $a = $a + "TH{border-width: 3px;padding: 2px;border-style:
> solid;border-color: white;background-color:yellow}"
> $a = $a + "TD{border-width: 3px;padding: 2px;border-style:
> solid;border-color: white;background-color:lightblue}"
> $a = $a + "</style>"
>
> get-eventlog -logname application | select Source, EntryType | group-object
> Source | where-object {$_.Group -match "Error"} | select Name, Count | sort
> Name | convertto-html -head $a –body "<H2>Application Errors</H2>" | Out-File
> f:\app.htm
>
> Invoke-Expression f:\app.htm
>
> I would like to alternate the row color for each data; that is one row is
> lightblue, the next white, then the next row is lightblue and the next one
> white and it goes on like that.
Jason1008,

Replace the ConvertTo-Html section with this:

Foreach-Object -Begin {
$a
"<H2>Application Errors</H2>"
"<table>"
"<tr><th>Name</th><th>Count</th></tr>"
$row = 0
} -Process {
$style = "style='background-color: white;'";

if ( $row % 2 -eq 0 )
{
$style = "style='background-color: lightblue;'";
}

"<tr><td {0}>{1}</td><td {0}>{2}</td></tr>" -f $style, $_.Name,
$_.Count

$row++
} -End {
"</table>"
} | Out-File f:\app.htm

Jeff
My System SpecsSystem Spec
Old 06-10-2008   #3 (permalink)
Shay Levi


 
 

Re: Alternate rows colors



$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 language="JavaScript">
window.onload=function(){
var TRs = document.getElementsByTagName("TR");
for (i=1; i <= TRs.length ; i++){
if (i % 2 == 1){
TRs[i].style.backgroundColor = "green";
} else {
TRs[i].style.backgroundColor = "red";
}
}
}
</script>
"@


get-eventlog -logname application | select Source, EntryType | group-object
Source | where {$_.Group -match "Error"} | select
Name, Count | sort Name | convertto-html -head $head –body "<H2>Application
Errors</H2>" | Out-File f:\app.htm

Invoke-Item d:\scripts\temp\gps.html



---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> This is the beginning of my script
>
> $a = "<style>"
> $a = $a + "BODY{background-color:white;}"
> $a = $a + "TABLE{border-width: 3px;border-style: solid;border-color:
> white;border-collapse: collapse;}"
> $a = $a + "TH{border-width: 3px;padding: 2px;border-style:
> solid;border-color: white;background-color:yellow}"
> $a = $a + "TD{border-width: 3px;padding: 2px;border-style:
> solid;border-color: white;background-color:lightblue}"
> $a = $a + "</style>"
> get-eventlog -logname application | select Source, EntryType |
> group-object Source | where-object {$_.Group -match "Error"} | select
> Name, Count | sort Name | convertto-html -head $a –body
> "<H2>Application Errors</H2>" | Out-File f:\app.htm
>
> Invoke-Expression f:\app.htm
>
> I would like to alternate the row color for each data; that is one row
> is lightblue, the next white, then the next row is lightblue and the
> next one white and it goes on like that.
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How do I filter rows in one csv file matching a value in another PowerShell
add an empty line to txt file every two rows. PowerShell
Windows Mail Stationery Stopped Working, Also Font colors and background colors... Vista mail
Add-on or tweak for multiple tab rows in IE7... Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46