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
- Host: GitHub
- URL: https://github.com/btbytes/csv2html
- Owner: btbytes
- License: bsd-3-clause
- Created: 2020-06-05T22:30:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-05T22:39:28.000Z (almost 6 years ago)
- Last Synced: 2025-07-17T17:23:41.404Z (8 months ago)
- Topics: csv, html, python, python3
- Language: Python
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```