[reportlab-users] Reportlab problem displaying japanese characters in a table
Andy Robinson
andy at reportlab.com
Fri Jun 12 07:32:52 EDT 2009
2009/6/12 Michael Dorrian <michael.dorrian at gmail.com>:
> Thanks for the replys...........
> Here is my function. I am just showing u what i had to do to display
> the first field of the table correctly from the returned rows of the
> sql.............there must be an easier way than this. The field
> headings display correctly. Its just the database data thats the
> problem.
You said earlier that you get an error message when running this. Can
you post the traceback? If it's in the table-building line, can you
put this on a separate line....?
str(..) requires its arguments to be ASCII, so whatever the content
encoding is in JPYRows[0][11], if it contains any non-ascii, it will
fail. Try getting the first field directly and converting it from
utf8 to unicode on a separate line and then assembling it. We'll then
know where it fails. e.g.
db_content = JPYRows[0][11]
unicode_content = db_content.decode('utf8')
t = Table(Paragraphs(...headers..., (unicode_content, ....)))
...if that fails, try the other Japanese encodings in plave of 'utf8'
- do you know anything about EUC or Shift-JIS?
BTW, all those steps you are going through are necessary. If you are
doing them in several parts of your program, you can hide them in a
function somewhere to make it more readable; every project I work on
tends to have a database connection already passed around, and I have
a utility function something like this...
def query(conn, sql_statement):
cur = conn.cursor()
cur.execute(sql_statement)
rows = cur.fetchall()
cur.close() #good idea with some DB APIs.
return rows
...so the actual code I'd work on from project to project looks more like...
table_data = [[headers]] + query(conn, 'SELECT blah blah....')
t = Table(table_data)
story.append(t)
--
Andy Robinson
CEO/Chief Architect
ReportLab Europe Ltd.
Media House, 3 Palmerston Road, Wimbledon, London SW19 1PG, UK
Tel +44-20-8545-1570
More information about the reportlab-users
mailing list