thombashi / pytablewriter

pytablewriter is a Python library to write a table in various formats: AsciiDoc / CSV / Elasticsearch / HTML / JavaScript / JSON / LaTeX / LDJSON / LTSV / Markdown / MediaWiki / NumPy / Excel / Pandas / Python / reStructuredText / SQLite / TOML / TSV.
https://pytablewriter.rtfd.io/
MIT License
610 stars 43 forks source link

Add custom stylesheet to html table #16

Closed domino-blake closed 4 years ago

domino-blake commented 5 years ago

Is it possible to add a custom stylesheet to html table? Looked through the docs but wasn't able to see any clear instructions

thombashi commented 4 years ago

Unfortunately, there is no functionality to do that currently. Did you expect an interface that can specify a class name to output table tags? or something else? Would you describe your expectations for more detail?

thombashi commented 4 years ago

@domino-blake You can output CSS with HtmlTablewriter/CssTablewriter of pytablewriter 0.51.0 or later. I'm not so sure this is what you expected though.

Example:

from pytablewriter import HtmlTableWriter

writer = HtmlTableWriter()
writer.table_name = "write_css"
writer.headers = ["int"]
writer.value_matrix = [[1]]
writer.write_table(write_css=True)

Output:

<style type="text/css">
    .write-css thead th:nth-child(1) {
        text-align: left;
    }
    .write-css tbody tr:nth-child(1) td:nth-child(1) {
        text-align: right;
    }
</style>
<table class="write-css" id="write_css">
    <caption>write_css</caption>
    <thead>
        <tr>
            <th>int</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
        </tr>
    </tbody>
</table>