An open API service indexing awesome lists of open source software.

https://github.com/btbytes/csv2html

A script to convert a CSV file to HTML file with some options
https://github.com/btbytes/csv2html

csv html python python3

Last synced: 8 months ago
JSON representation

A script to convert a CSV file to HTML file with some options

Awesome Lists containing this project

README

          

# csv2html
A script to convert a CSV file to HTML file with some options.Reads a CSV File and writes the output to the terminal.

Options:

1. Field delimiter
2. Quote character
3. HTML Table caption
4. Page title
5. First row has header information.

```
$ ./csv2html.py -h
usage: csv2html.py [-h] [--delimiter DELIMITER] [--quotechar QUOTECHAR]
[--title TITLE] [--caption CAPTION] [--header]
csvfile

CSV to HTML converter.

positional arguments:
csvfile

optional arguments:
-h, --help show this help message and exit
--delimiter DELIMITER
Field delimiter. Default is , .
--quotechar QUOTECHAR
Quote Character. Deault is nothing
--title TITLE Page title. Will be printed in h1 tag.
--caption CAPTION Table caption.
--header data has header. First row will be "th".
```

Example input:

```csv
mpg,cylinders,displacement,horsepower,weight,acceleration,model_year,origin,name
18,8,307,130,3504,12,70,1,chevrolet chevelle malibu
15,8,350,165,3693,11.5,70,1,buick skylark 320
18,8,318,150,3436,11,70,1,plymouth satellite
```

Command: `./csv2html.py example.csv --header --caption "Car MPGs" > example.html`

Output:

```HTML

table {
border-collapse: collapse;
margin-bottom: 10px;
}

td,
th {
padding: 6px;
text-align: left;
}

thead {
border-bottom: 1px solid var(--border);
}

tfoot {
border-top: 1px solid var(--border);
}

tbody tr:nth-child(even) {
background-color: var(--background-alt);
}

Car MPGs

mpg
cylinders
displacement
horsepower
weight
acceleration
model_year
origin
name

18
8
307
130
3504
12
70
1
chevrolet chevelle malibu

15
8
350
165
3693
11.5
70
1
buick skylark 320

18
8
318
150
3436
11
70
1
plymouth satellite

```