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:


Screenshot of HTML result

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

$css = @"

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; }


$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 


Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.