如何在HTML输出中使列加粗

时间:2015-04-01 17:51:07

标签: html css powershell

以下是我的PowerShell脚本。它生成一个格式良好的HTML表。我想把一个列加粗(Full%column)。我不能为我的生活想办法。

我尝试在不同的地方插入粗体标签并尝试使用替换的方法,但由于列中的数字发生变化,我无法想到这样做的方法。

$symmid = 1555
$command1 = symfast -sid $symmid list -association -demand
$command2 = symcfg -sid $symmid list -thin -pool -detail -gb
$basedir = "C:\ts\Scripts"
$timestamp = Get-Date -Format ddMMyyyy
$CSSFile = "$basedir\csstemplate.css"

$css = get-content $CSSFile


$command1 > $basedir\archive_vp\archive_$timestamp.txt
$command2 > $basedir\archive_pool\archive_$timestamp.txt

$regex = '(?ms)P O O L S(.+?)\r\n\s*\r\n'
$command2 = $command2 -join "`r`n"
$command2 = [regex]::Matches($command2,$regex) | foreach {$_.groups[1].value}
$command2 = $command2 -split "`r`n" | select -Skip 5

$command2Format = $command2 | % {
  $column = $_ -split ' +'
  $hash = [ordered]@{
   'Pool Name'  = $column[0]
   'Flags PTECSL'  = $column[1]
   'Dev Config'    = $column[2]
   'Total GBs'      = $column[3]
   'Usable GBs'    = $column[4]
   'Free GBs'       = $column[5]
   'Used GBs'       = $column[6]
   'Full (%)'       = $column[7]
   'Subs (%)'       = $column[8]
   'Comp (%)'       = $column[9]
   'Shared GBs'    = $column[10]


 }
 New-Object -Type PSCustomObject -Property $hash
} | ConvertTo-Html -Head $a


function get-css
{
    foreach($line in $css)
    {
        $style += $line
    }
    return $style
}


$style = "<style>"
$style = get-css
$style += "</style>"

$report = "<html><head>$style</head><body>$command2Format</body></html>"


$report | Out-File $basedir\test.html
Invoke-Expression $basedir\test.html

输出:

enter image description here

2 个答案:

答案 0 :(得分:2)

你能指望CSS3吗?如果是这样,您可以使用:nth-Child()选择器。详情请见http://www.w3schools.com/cssref/sel_nth-child.asp

答案 1 :(得分:1)

你应该能够按照这个基本的例子来得到你想要的东西

$a = @"
<style>
    TD:nth-child(1){font-weight: bold}
</style>
"@

Get-ChildItem c:\temp -Directory | Select Name,lastwritetime | ConvertTo-Html -Head $a | Set-Content c:\temp\file.html 
ii c:\temp\file.html 

因此,nth-child(1)定义第一列数据的文字加粗。你应该能够在第7列完成同样的事情。

是的,就像Tim Ferrill所说,你需要浏览器支持,但这不应该是一个很高的订单。

Sample Output

相关问题