标题: [问题求助] 在IE浏览器控件中显示powershell的表格内容的输出 [打印本页]
作者: 5i365 时间: 2022-9-25 16:59 标题: 在IE浏览器控件中显示powershell的表格内容的输出
下面的代码, 可以在IE浏览器控件中显示PS的输出, 遇到一个问题: 只有把红色字部分删除才可以显示,
但是红色字部分可以设置筛选并对齐属性, 求大侠指点, 多谢
Add-Type -AssemblyName System.Windows.Forms
$Column1 = @{ expression = "Name"; width = 50; label = "服务名"; alignment = "right" }
$Column2 = @{ expression = "DisPlayname"; width = 50; label = "显示名"; alignment = "left" }
$html = Get-Service | Format-Table $Column1, $Column2 | ConvertTo-Html
$webbrowser1 = New-Object 'System.Windows.Forms.WebBrowser'
$webbrowser1.Dock = 'Fill'
$webbrowser1.DocumentText = $html
$form1 = New-Object 'System.Windows.Forms.Form'
$form1.ClientSize = '600, 460'
$form1.StartPosition = 'CenterScreen'
$form1.Text = 'IE浏览器'
$form1.Controls.Add($webbrowser1)
$form1.ShowDialog()
作者: idwma 时间: 2022-9-29 18:34
- Add-Type -AssemblyName System.Windows.Forms
-
- $Column1 = @{ expression = "Name"; width = 50; label = "服务名"; alignment = "right" }
- $Column2 = @{ expression = "DisPlayname"; width = 50; label = "显示名"; alignment = "left" }
- $html = Get-Service | ConvertTo-Html -property name,DisPlayname
- $html=$html -replace '(?<=<tr><td)(?=>)',' style="text-align:right;"'
-
- $webbrowser1 = New-Object 'System.Windows.Forms.WebBrowser'
- $webbrowser1.Dock = 'Fill'
- $webbrowser1.DocumentText = $html
-
- $form1 = New-Object 'System.Windows.Forms.Form'
- $form1.ClientSize = '600, 460'
- $form1.StartPosition = 'CenterScreen'
- $form1.Text = 'IE浏览器'
- $form1.Controls.Add($webbrowser1)
-
- $form1.ShowDialog()
复制代码
作者: 5i365 时间: 2022-9-29 20:36
回复 2# idwma
多谢大侠支招, 效果真是不错!
能显示表格线条吗? ConvertTo-Html 中好像没有这个参数
作者: idwma 时间: 2022-9-29 21:25
回复 3# 5i365
关键字html语言表格显示边框,可以搜到很多
作者: 5i365 时间: 2022-9-29 22:02
回复 4# idwma
多谢指引, 现在漂亮多了
- $css = @"
- <div style="overflow-x:auto;">
- <style>
- table {
- border-collapse: collapse;
- border:1px solid skyblue;
- }
- th, td {
- text-align: left;
- padding: 8px;
- border:1px solid skyblue;
- }
-
- th {
- border-width: 1px;
- border-color: black;
- background-color: #E20074;
- }
- </style>
- "@
- Add-Type -AssemblyName System.Windows.Forms
-
- Get-Service | ConvertTo-Html -property name, DisPlayname -Head $css| tee -var html
-
- $webbrowser1 = New-Object 'System.Windows.Forms.WebBrowser'
- $webbrowser1.Dock = 'Fill'
- $webbrowser1.DocumentText = $html
-
- $form1 = New-Object 'System.Windows.Forms.Form'
- $form1.ClientSize = '600, 460'
- $form1.StartPosition = 'CenterScreen'
- $form1.Text = 'IE浏览器'
- $form1.Controls.Add($webbrowser1)
-
- $form1.ShowDialog()
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |