Insert image in Excel file(xlwt) in GAE

2,492 views
Skip to first unread message

Nijin Narayanan

unread,
Jan 5, 2012, 6:20:08 AM1/5/12
to python...@googlegroups.com, google-appe...@googlegroups.com, sjma...@lexicon.net
Hi,

I need to insert an Bitmap image in Excel file(creating using xlwt). i tried to insert using insert_bimap() method but it return IO Error.

Error:
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 701, in __call__
    handler.get(*groups)
  File "C:\apps\test.py", line 44, in get
    ws0.insert_bitmap('images/logo.gif', 2, 2)
  File "C:\apps\xlwt\Worksheet.py", line 1034, in insert_bitmap
    bmp = Bitmap.ImDataBmpRecord(filename)
  File "C:\apps\xlwt\Bitmap.py", line 255, in __init__
    self.width, self.height, self.size, data = _process_bitmap(filename)
  File "C:\apps\xlwt\Bitmap.py", line 195, in _process_bitmap
    fh = file(bitmap, "rb")
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 578, in __init__
    raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'images/logo.gif'

Code:
class MainHandler(webapp.RequestHandler):
    def get(self):     
            wb = Workbook()
            ws0 = wb.add_sheet('Sheet 1')

            ws0.write(0, 2, "chg wid: none")
            ws0.insert_bitmap('images/logo.gif', 2, 2)

            self.response.headers['Content-Type'] = 'application/ms-excel'
            self.response.headers['Content-Transfer-Encoding'] = 'Binary'
            self.response.headers['Content-disposition'] = 'attachment; filename="Sample.xls"'
            wb.save(self.response.out)

Please let me know if Any Workaround for this ?

Cheers! ,  

NN


lzantal

unread,
Jan 5, 2012, 4:19:25 PM1/5/12
to python...@googlegroups.com, google-appe...@googlegroups.com, sjma...@lexicon.net
Hi,

I got that error too, I switched over to use absolute path and it works fine now.
So instead of ws0.insert_bitmap('images/logo.gif', 2, 2) use
ws0.insert_bitmap('C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\images/logo.gif', 2, 2)
I am of course just assuming thats the right path.


lzantal

> --
> You received this message because you are subscribed to the Google Groups "python-excel" group.
> To post to this group, send an email to python...@googlegroups.com.
> To unsubscribe from this group, send email to python-excel...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.

Nijin Narayanan

unread,
Jan 6, 2012, 12:12:13 AM1/6/12
to python...@googlegroups.com, google-appe...@googlegroups.com
But How do i give the System path ? My Apps will host in app engine.

Please share if anyone have any details.

Cheers! ,  

NN

Laszlo Antal

unread,
Jan 6, 2012, 12:27:53 AM1/6/12
to python...@googlegroups.com, python...@googlegroups.com
Hi,

Have you tried os.path.abspath(__file__) ?
It will return the absolute path to the current file.

lzantal

Nijin Narayanan

unread,
Jan 6, 2012, 7:50:50 AM1/6/12
to python...@googlegroups.com
That was worked. Thanks lzantal :)

Cheers! ,  

NN

Sreedhar

unread,
Dec 21, 2012, 3:54:45 AM12/21/12
to python...@googlegroups.com, python...@googlegroups.com
Hei Carlos

If the file has dependency
Or its being used or locked by any other process we would get that error




On 9 Dec 2012, at 07:23 AM, carlos gg <carlo...@gmail.com> wrote:

Hi, I am trying to do the same and still could not get it to work even after reading this thread (!). So the way to do it is:

ws0.insert_bitmap(os.path.abspath('images/logo.gif'), 2, 2)

??

I tried something like that for my case and it still said "file not accessible"

Thank you!
To view this discussion on the web, visit https://groups.google.com/d/msg/python-excel/-/JofykDULSsYJ.

carlos gg

unread,
Dec 26, 2012, 7:02:02 AM12/26/12
to python...@googlegroups.com
Thank you Sri! I put it in the root directory of the app instead of /images and it worked somehow. Happy New Year from Florida.

Sri Sreedhar

unread,
Dec 26, 2012, 1:25:19 PM12/26/12
to python...@googlegroups.com, carlo...@gmail.com
You are Welcome Carlos,
Happy New Year to you too. :)

To view this discussion on the web, visit https://groups.google.com/d/msg/python-excel/-/nfqLsqujtfkJ.
Reply all
Reply to author
Forward
0 new messages