-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcel2StackExchangeTable.ps1
More file actions
46 lines (33 loc) · 980 Bytes
/
Excel2StackExchangeTable.ps1
File metadata and controls
46 lines (33 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# In a shortcut, call like
# Target: "C:\Program Files (x86)\PowerShell\7\pwsh.exe" .\Excel2StackExchange.ps1
# Start In: "%userprofile%\repos\WindowsTools"
# Excel to Stack Exchange Table
# First row must not contain any cells with multiple lines.
# Write-Host "
# --------------------------------
# "
$sInput = Get-Clipboard -Raw
$arrIn = $sInput -split "`r`n"
# Get first (header) row
$header = $arrIn[0] -split "`t"
$arrOut = @()
$arrOut += "|$($header -join "|")|"
$s = "|"
for ($i = 0; $i -lt $header.length; $i++) {
$s += "---|"
}
$arrOut += $s
# Get body rows
for ($i = 1; $i -lt $arrIn.length - 1; $i++) {
$thisRow = $arrIn[$i] -split "`t"
for ($j = 0; $j -lt $thisRow.length; $j++) {
$thisRow[$j]
$thisRow[$j] = $thisRow[$j].replace("`n","<br >")
if ($thisRow[$j] -eq "") {
$thisRow[$j] = " "
}
}
$arrOut += "|$($thisRow -join "|")|"
}
$sOutput = $arrOut -join "`n"
Set-Clipboard $sOutput