backcage.pages.dev




Tr th td

I made a lot of script to find a nice way to automate the creation of nice html tables using Python. This is the last one. I think this is a nice script. The result is this:

I think it&#;s nice. You can change the structure of the table changing this:

conto = """ <tr> <td data-th="Movie Title">{}</td> <td data-th="Genre">{}</td> <td data-th="Year">{}</td> <td data-th="Gross">{}</td> </tr>"""*2

This is where the giorno go. The data, for example, can be these:

replace = """Banca x c/c Versamento € Denaro in cassa prelievo depositato in banca €"""

There are 2 rows (if you want more row, multiplicate for 3, 4 &#; the conto variable).

You just have to write on each line the 4 giorno for the first line and another 4 giorno for line after those. If you want to leave a cell empty, leave the line empty.

Here is the whole code. Most of it is css. The python code is at the end, just 10ish line of code.

import os html = """<style> @import "?family=Montserrat,,"; .rwd-table { margin: 1em 0; min-width: px; } .rwd-table tr { border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; } .rwd-table th { display: none; } .rwd-table td { display: block; } .rwd-table td:first-child { padding-top: .5em; } .rwd-table td:last-child { padding-bottom: .5em; } .rwd-table td:before { content: attr(data-th) ": "; font-weight: bold; width: em; display: inline-block; } @media (min-width: px) { .rwd-table td:before { display: none; } } .rwd-table th, .rwd-table td { text-align: left; } @media (min-width: px) { .rwd-table th, .rwd-table td { display: table-cell; padding: em .5em; } .rwd-table th:first-child, .rwd-table td:first-child { padding-left: 0; } .rwd-table th:last-child, .rwd-table td:last-child { padding-right: 0; } } h1 { font-weight: normal; letter-spacing: -1px; color: #E; } .rwd-table { background: #E; color: #fff; border-radius: .4em; overflow: hidden; } .rwd-table tr { border-color: #f; } .rwd-table th, .rwd-table td { margin: .5em 1em; } @media (min-width: px) { .rwd-table th, .rwd-table td { padding: 1em !important; } } .rwd-table th, .rwd-table td:before { color: #dd5; } </style> <script> e = e || function(t) {}; </script> <script> if ((/type=embed/gi)) { ssage("resize", "*"); } </script> <h1>Libro giornale</h1> <table class="rwd-table"> <tr> <table class="rwd-table"> <tr> <th>Conto</th> <th>Descrizione</th> <th>Dare</th> <th>Avere</th> </tr> <conti> </table>""" fattura = """ <tr> <td data-th="Movie Title">{}</td> <td data-th="Genre">{}</td> <td data-th="Year">{}</td> <td data-th="Gross">{}</td> </tr>"""*2 replace = """Banca x c/c Versamento € Denaro in cassa prelievo depositato in banca €""" replace = ("\n") print(replace) conto = (*replace) html = e("<conti>", conto) with open(myfile := "", "w") as file: (html) ile(myfile)

A version for &#;csv&#; type of data, comma separated value

This version let you input the giorno separated by comma. Perhaps it&#;s more handy

import os html = """<style> @import "?family=Montserrat,,"; .rwd-table { margin: 1em 0; min-width: px; } .rwd-table tr { border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; } .rwd-table th { display: none; } .rwd-table td { display: block; } .rwd-table td:first-child { padding-top: .5em; } .rwd-table td:last-child { padding-bottom: .5em; } .rwd-table td:before { content: attr(data-th) ": "; font-weight: bold; width: em; display: inline-block; } @media (min-width: px) { .rwd-table td:before { display: none; } } .rwd-table th, .rwd-table td { text-align: left; } @media (min-width: px) { .rwd-table th, .rwd-table td { display: table-cell; padding: em .5em; } .rwd-table th:first-child, .rwd-table td:first-child { padding-left: 0; } .rwd-table th:last-child, .rwd-table td:last-child { padding-right: 0; } } h1 { font-weight: normal; letter-spacing: -1px; color: #E; } .rwd-table { background: #E; color: #fff; border-radius: .4em; overflow: hidden; } .rwd-table tr { border-color: #f; } .rwd-table th, .rwd-table td { margin: .5em 1em; } @media (min-width: px) { .rwd-table th, .rwd-table td { padding: 1em !important; } } .rwd-table th, .rwd-table td:before { color: #dd5; } </style> <script> e = e || function(t) {}; </script> <script> if ((/type=embed/gi)) { ssage("resize", "*"); } </script> <h1>Libro giornale</h1> <table class="rwd-table"> <tr> <table class="rwd-table"> <tr> <th>Conto</th> <th>Descrizione</th> <th>Dare</th> <th>Avere</th> </tr> <conti> </table>""" # ================================== Python === replace = """ Banca x c/c, Versamento, €,, Soldi in cassa, prelievo depositato in istituto, €, Merci c/acquisto, ricevuta ft. n. 3, €,, ,,,, IVA a Fiducia, iva su ft. nr. 3, 22 €,, Debiti v/fornitori, ft. 3,, € """ replace = (",") lines = len(replace) // 4 calcolo = """ <tr> <td data-th="Movie Title">{}</td> <td data-th="Genre">{}</td> <td data-th="Year">{}</td> <td data-th="Gross">{}</td> </tr>"""*lines print(replace) conto = (*replace) html = e("<conti>", conto) with open(myfile := "", "w") as file: (html) ile(myfile)

Video about this code to make html table with Python

A version that uses pandas to make html tables from Excel

Go here to read about how to

  • make a table into Excel
  • grab it with Pandas
  • get some style to it
  • make an html table with &#;style&#;

Click here to create a table with style from Excel.

Utilities