Tek Info
asked on
Add blank lines in html formatting in powershell
I want to add 2 blank lines before and 2 blank lines after this html table formatting in powershell
$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>
use `r`n
$a="HK`r`n`r`nHainKurt"
echo $a
>>>HK
HainKurt
or you can use margin for table
demo
https://jsfiddle.net/HainKurt/qa3urfwv/
TABLE {
border-width: 1px;
border-style: solid;
border-color: black;
border-collapse: collapse;
margin-top: 2em;
margin-bottom: 2em;
}
not sure where and how do you need this space...demo
https://jsfiddle.net/HainKurt/qa3urfwv/
On a side note: there's a PowerShell method exactly for long string blocks like that; it's called "Here-String".
A Here-String starts with @" anywhere in the line and a line break, and ends with "@ at the very beginning of a line. Anything between there will be part of the string.
Works with @' and '@ respectively as well, the same way it does for string variables.
And you should use self-explaining variable names.
So the equivalent to what you posted above would be this:
A Here-String starts with @" anywhere in the line and a line break, and ends with "@ at the very beginning of a line. Anything between there will be part of the string.
Works with @' and '@ respectively as well, the same way it does for string variables.
And you should use self-explaining variable names.
So the equivalent to what you posted above would be this:
$style = @'
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 0px;border-style: solid;border-color: black;}
TD {border-width: 1px;padding: 0px;border-style: solid;border-color: black;}
</style>
'@
ASKER
@oBdA
Thanks very much however now the border is gone.
Thanks very much however now the border is gone.
I guess we do not get what you are trying to do...
what border are you referring to?
any code\link\screenshot?
what border are you referring to?
any code\link\screenshot?
ASKER
Thanks @HainKurt
The border referred to in the script.. it's a black border.
Please see below.
The border referred to in the script.. it's a black border.
Please see below.
$a = "<style>"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;}"
$a = $a + "</style>
did you add "margin-top: 2em; margin-bottom: 2em;" and try
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse; margin-top: 2em; margin-bottom: 2em;}"
also you can combine all border properties into one
$a = $a + "TABLE{border: 1px solid black; border-collapse: collapse; margin-top: 2em; margin-bottom: 2em;}"
sımplified version
TABLE {
border: 1px solid black;
border-collapse: collapse;
margin: 2em 0 2em 0;
}
TH {
padding: 0px;
border: 1px solid black;
}
TD {
padding: 0px;
border: 1px solid black;
}
https://jsfiddle.net/HainKurt/qa3urfwv/
Adding <br> before or after the <table>...</table> won't change the style, so I guess you're referring to the style inside a Here-String?
You will still need to embed the $style variable into the <head> of the html you create.
Here's a complete sample how it could look like.
You'll probably create the table dynamically, here's it's just some static html.
You will still need to embed the $style variable into the <head> of the html you create.
Here's a complete sample how it could look like.
You'll probably create the table dynamically, here's it's just some static html.
$style = @'
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH {border-width: 1px;padding: 0px;border-style: solid;border-color: black;}
TD {border-width: 1px;padding: 0px;border-style: solid;border-color: black;}
</style>
'@
$table = @"
<table>
<tr><th>Column 1</th><th>Column 2</th></tr>
<tr><th>Row 1 Col 1</th><th>Row 1 Col 2</th></tr>
<tr><th>Row 2 Col 1</th><th>Row 2 Col 2</th></tr>
</table>
"@
$html = @"
<html>
<head>
$($style)
</head>
<body>
Some line before the table<br>
<br>
<br>
$($table)
<br>
<br>
Some line after the table<br>
</body>
</html>
"@
$html | Set-Content -Path C:\Temp\TestTable.html
Invoke-Item C:\Temp\TestTable.html
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
What you posted is just the style information for table, not the table itself.