[reportlab-users] Reportlab problem displaying japanese characters in a table
Michael Dorrian
michael.dorrian at gmail.com
Fri Jun 12 07:38:29 EDT 2009
Hi Andy,Thanks for this information. Sorry i didnt get an error when i just
put the string in the table directly from sql queried returned rows but it
displayed black squares instead of the japanese characters which was not
correct..so in order to display the data correctly i encoded it in a
paragrph and then nested it in the table...thanks for the tips....will try
again and may ask for your help again if needed..but thanks very much for
the response.
Regards,
Mike
On Fri, Jun 12, 2009 at 8:32 PM, Andy Robinson <andy at reportlab.com> wrote:
> 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
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20090612/b45f2491/attachment.htm>
More information about the reportlab-users
mailing list