Featured image of post Mini-Blog: Creating HTML files from CSV

Mini-Blog: Creating HTML files from CSV

We use a documentation system that only allows CSV exports, which gets annoying when tyring to supply clients with some form of data out of it. To resolve I rewrote the script by Brandon Everhardt to take all CSV files from a folder and export them into a single readable HTML file. It’s a very quick and dirty script, using the ConvertTo-HTML function to make a somewhat more readable approach.

The result looks like this:

To create the HTML file, here is the very quick and dirty code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
$css = @"


<style>
h1, h5, th { text-align: center; font-family: Segoe UI; }
table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge lime ; }
th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; }
td { font-size: 11px; padding: 5px 20px; color: #000; }
tr { background: #b8d1f3; }
tr:nth-child(even) { background: #dae5f4; }
tr:nth-child(odd) { background: #b8d1f3; }
</style>

"@

$csvs = get-childitem "C:\CSVs" -filter *.csv -Recurse
$outputfile = "C:\Temp\Document.html"
foreach($csv in $csvs){
Import-CSV $csv.FullName | ConvertTo-Html -Head $css -Body "<h1>Filename: $csv</h1>" | Out-File $outputfile -Append

}

All blogs are posted under AGPL3.0 unless stated otherwise
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy