数组转换为html表

数组转换为html表

如何将PowerShell中的简单哈希数组转换为HTML表?

$array = @{

"Name" = "My Name"
"Surname" = "My Surname"
"Address" = "My Address"
"DateOfBirth" = "My Date Of Birth"
"Hobby" = "My Hobby"
 "Age" = "My Age"
 }

html - PowerShell:将数组转换为html表-LMLPHP

然后继续添加行?有人做到过吗?下面,我将根据几个在线论坛提供到目前为止我已经尝试过的示例:
[System.Management.Automation.PSCustomObject]$array | ConvertTo-Html
-Fragment


New-Object psobject -Property $array | ConvertTo-Html -Fragment


$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -Fragment


 $array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment


$array | Select 'Name','Surname','Address','DateOfBirth','Hobby', 'Age' | ConvertTo-HTML -as Table -Fragment | Out-String


$table = $array.GetEnumerator() | ConvertTo-Html -Fragment -As Table

html - PowerShell:将数组转换为html表-LMLPHP
$table = $array.GetEnumerator() | select "Name", "Surname", "Address", "DateOfBirth", "Hobby", "Age" | ConvertTo-Html -Fragment -As Table

html - PowerShell:将数组转换为html表-LMLPHP

如您所见,有许多不同的方法,但是没有一种方法可以成功:-(

最佳答案

你的意思是这样的吗?

$table = [PSCustomobject]$array| ConvertTo-Html -Fragment -As Table
$table
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>Name</th><th>Age</th><th>Surname</th><th>DateOfBirth</th><th>Hobby</th><th>Address</th></tr>
<tr><td>My Name</td><td>My Age</td><td>My Surname</td><td>My Date Of Birth</td><td>My Hobby</td><td>My Address</td></tr>
</table>

您想从哪个来源添加行?

10-07 14:18