WebJEA
WebJEA copied to clipboard
ConvertTo-HTML table to output
Hi,
Is it possible to do ConvertTo-HTML -Fragment inside PS and pass it to web page? I would love to give users some tables, but i don't see simple way to do so.
And if there would be .pstable in PsOutput.css it would be a master piece.
I'll add this as a feature to consider. I'll have to do some testing to see if it exposes any js injection vulnerabilities.
Any way to do table formatting would be great. Currently when I try to color items in an object by wrapping an item in '[[span|psred|SOMETEXT]]' it messes up the format-table -AutoSize when the span is replaced on output.
It is possible, albeit only using multiple [[span]] together with different CSS classes (which you can conveniently style in psoutput.css) to essentially fake the table.
Here is what I do (where $my_data further down holds the table-like data):
$columns = @("Column1", "Column2", "Column3")
$html = "[[span|table|"
$html = $html + "[[span|table-caption|My Table]]"
$html = $html + "[[span|table-header|"
# add header columns
foreach ($column in $columns) {
$html = $html + "[[span|table-header-cell|" + $column + "]]"
}
# close header
$html = $html + "]]"
# add body
$html = $html + "[[span|table-body|"
# add rows
foreach ($row in $my_data) {
$html = $html + "[[span|table-row|"
# add cells
foreach ($column in $columns) {
$html = $html + "[[span|table-body-cell|" + $row.psobject.Properties[$column].Value + "]]"
}
# close row
$html = $html + "]]"
}
# close body
$html = $html + "]]"
# close table
$html = $html + "]]"
# Output the formatted string:
$html
Now in the psoutput.css file you can style the classes, for example:
.table {
width: 100%;
display: table;
}
.table-caption{
display: table-caption;
text-align: center;
font-size: 1.0rem;
font-weight: bold;
}
.table-header{
display: table-header-group;
background-color: gray;
font-weight: bold;
font-size: 0.8rem;
}
.table-header-cell{
display: table-cell;
padding: 4px;
text-align: justify;
border-bottom: 2px solid black;
}
.table-body{
display: table-row-group;
}
.table-row{
display: table-row;
}
.table-body-cell{
display: table-cell;
padding: 4px;
border-bottom: 1px solid black;
}
That's really cool. I just tried it out and like it. The only problem is that it doesn't handle a link in a table-body-cell. [[span|table-body-cell|[[a|url|display]]]] Looks like it isn't putting the into the output correctly. Opening a separate defect.