471,339 Members | 1,284 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,339 software developers and data experts.

how to generate html table from "table" data?


Hi group,
I would like to convert the output of the SQL query, or more generally
I would like to convert any "table" data to the html table.

I would like to set some rules to format cells, columns or rows (font,
colour etc.) of the html table, according to the values in the
specific cells.

Googling for a while I have found only this tool:
http://pasko.net/PyHtmlTable/

Your tips to some other tools or/and your suggestion how to solve
above mentioned will be very helpful.

Thanks and regards

Petr Jakes
Dec 25 '07 #1
7 3596
pe************@gmail.com a écrit :
Hi group,
I would like to convert the output of the SQL query, or more generally
I would like to convert any "table" data to the html table.
There's MoreThanOneWayToDoIt... from simple string formatting to a
full-blown template engine.
I would like to set some rules to format cells, columns or rows (font,
colour etc.) of the html table, according to the values in the
specific cells.
<ot>
Markup should only convey semantic informations - presentation is best
done using css. IOW : presentation-related stuff in the html should be
restricted to css class declarations.
</ot>
Googling for a while I have found only this tool:
http://pasko.net/PyHtmlTable/

Your tips to some other tools or/and your suggestion how to solve
above mentioned will be very helpful.
As I said, wrt/ html generation, there are quite a lot of possible
solutions - FWIW, generating an html table from a set of tabular data is
nothing difficult. So without more information on the context, it's hard
to give any valuable advice. Are you doing a web application ? If yes,
you should already use a template engine, so just use it. Else, why is
your application generating html at all ?
Dec 26 '07 #2
petr.jakes....@gmail.com a écrit :
>
Hi group,
I would like to convert the output of the SQL query, or more generally
I would like to convert any "table" data to the html table.
I would like to set some rules to format cells, columns or rows (font,
colour etc.) of the html table, according to the values in the
specific cells.
Why not try writing your own code for this first?
If nothing else, it'll help you learn more, and may also help you
understand better, the other options.

Vasudev Ram
-----------
Dancing Bison Enterprises
Software consulting and training
Biz site: http://www.dancingbison.com
Blog (on software innovation): http://jugad.livejournal.com
Quick and easy PDF creation toolkit: http://www.dancingbison.com/products.html

Dec 26 '07 #3
>
Why not try writing your own code for this first?
If nothing else, it'll help you learn more, and may also help you
understand better, the other options.

Vasudev Ram
Thanks for your reply even it was not really helpful.
Of course some attempts to generate html from tabular data are behind
me. I am trying to find help here, because I think I am not the first
one, who is trying to "generate" html tables.

The purpose of my effort is to automatically and repeatedly read ¦QL
table and save the output of the SQL SELECT to the file in the html
format. Such a "reports" can be read by user using web browser later
on.

I was just trying to find if somebody here can point me to the
existing tool, which is suitable for such a task.

Anyway thank you for trying me help.

Petr Jakes
Dec 26 '07 #4
pe************@gmail.com a écrit :
Vasudev Ram wrote:
>>Why not try writing your own code for this first?
If nothing else, it'll help you learn more, and may also help you
understand better, the other options.

Thanks for your reply even it was not really helpful.
The answers boil down to:
- use the templating engine that comes with your web framework
or
- use whatever templating engine you like
or
- just do it by hand

The remaining work is obviously such a no-brainer that there's no need
for a specific package, and so application specific that there's
probably nothing like a one-size-fits-all answer. IOW : you're not
likely to find more "helpful" answer - and your above comment won't
help. FWIW, I just wrote a function generating an html table from a list
of header and a list of rows. I wrote the most Q&D, straightforward,
braindead way, it's 17 lines long, doesn't even need an import
statement, and took me less than 2 minutes to write - that is, far less
work than reading your post and answering it.
Dec 26 '07 #5
Dennis,
Thank you very much for your code snippet.
I will try to install CherryTemplate and use it.

I did not work with any template tool before and I am not the *****
class programmer as other people here, so my questions maybe look
"strange" or "stup..".

I didn't mean to offend somebody here and I am really grateful for all
replies.

Thank you

Petr Jakes
Dec 26 '07 #6
Bruno Desthuilliers wrote:
pe************@gmail.com a écrit :
Vasudev Ram wrote:
>>Why not try writing your own code for this first?
If nothing else, it'll help you learn more, and may also help you
understand better, the other options.
Thanks for your reply even it was not really helpful.

The answers boil down to:
- use the templating engine that comes with your web framework
or
- use whatever templating engine you like
or
- just do it by hand

The remaining work is obviously such a no-brainer that there's no need
for a specific package, and so application specific that there's
probably nothing like a one-size-fits-all answer. IOW : you're not
likely to find more "helpful" answer - and your above comment won't
help. FWIW, I just wrote a function generating an html table from a list
of header and a list of rows. I wrote the most Q&D, straightforward,
braindead way, it's 17 lines long, doesn't even need an import
statement, and took me less than 2 minutes to write - that is, far less
work than reading your post and answering it.
Hi.
Bruno, could you please post those 17 lines? I'm not actually doing HTML
work but I would find it interesting going through your code.

TIA

Dec 27 '07 #7
Ricardo Aráoz a écrit :
Bruno Desthuilliers wrote:
(snip)
>FWIW, I just wrote a function generating an html table from a list
of header and a list of rows. I wrote the most Q&D, straightforward,
braindead way, it's 17 lines long, doesn't even need an import
statement, and took me less than 2 minutes to write - that is, far less
work than reading your post and answering it.

Hi.
Bruno, could you please post those 17 lines? I'm not actually doing HTML
work but I would find it interesting going through your code.
I'm afraid I throw that code away - as I said, this was braindead Q&D
code, and certainly not even worth the time you'd spend reading it. But
I can rewrite it if you want:

def generate_html_table(headers, rows):
html = []

if headers:
html.append("<tr>")
for header in headers:
html.append("<th>%s</th>" % header)
html.append("</tr>")

if rows:
for row in rows:
html.append("<tr>")
for cell in row:
html.append("<td>%s</td>" % cell)
html.append("</tr>")

if html:
html = ["<table>"] + html + ["</table>"]

return "\n".join(html)
Nothing interesting here, as you can see. And if you're going to do
anything serious in web development, you'll be better using a templating
system anyway.
Dec 28 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Sugapablo | last post: by
4 posts views Thread by cardinallijr | last post: by
reply views Thread by Kamal Ahmed | last post: by
4 posts views Thread by McGowan | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.