[pyxl] instert picture to excel

342 views
Skip to first unread message

Jannis Syntychakis

unread,
May 7, 2010, 5:31:42 AM5/7/10
to python-excel
Hallo everybody,

maybe something can help me with this:

I generate a plot with matplotlib. I save it as an .png image called
plot.png.

now i want to get that image into excel. (so i do this I'm using
xlwt) .

plt.savefig('plot.png')
ws.insert_bitmap('plot.png', 35, 7)

if i run i get this message:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Python26\ginput[2].py", line 753, in Homogeen_SNR_CNR
ws.insert_bitmap('plot.png', 35, 7)
File "C:\Python26\lib\site-packages\xlwt\Worksheet.py", line 1034,
in insert_bitmap
bmp = Bitmap.ImDataBmpRecord(filename)
File "C:\Python26\lib\site-packages\xlwt\Bitmap.py", line 255, in
__init__
self.width, self.height, self.size, data =
_process_bitmap(filename)
File "C:\Python26\lib\site-packages\xlwt\Bitmap.py", line 206, in
_process_bitmap
raise Exception("bitmap doesn't appear to to be a valid bitmap
image.")
Exception: bitmap doesn't appear to to be a valid bitmap image.
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Python26\ginput[2].py", line 753, in Homogeen_SNR_CNR
ws.insert_bitmap('plot.png', 35, 7)
File "C:\Python26\lib\site-packages\xlwt\Worksheet.py", line 1034,
in insert_bitmap
bmp = Bitmap.ImDataBmpRecord(filename)
File "C:\Python26\lib\site-packages\xlwt\Bitmap.py", line 255, in
__init__
self.width, self.height, self.size, data =
_process_bitmap(filename)
File "C:\Python26\lib\site-packages\xlwt\Bitmap.py", line 206, in
_process_bitmap
raise Exception("bitmap doesn't appear to to be a valid bitmap
image.")
Exception: bitmap doesn't appear to to be a valid bitmap image.


if i go to the map where i saved the image i CAN open it.

thanks in advance

--
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.

John Machin

unread,
May 7, 2010, 9:17:10 AM5/7/10
to python...@googlegroups.com
On 7/05/2010 7:31 PM, Jannis Syntychakis wrote:

>
> I generate a plot with matplotlib. I save it as an .png image called
> plot.png.
>
> now i want to get that image into excel. (so i do this I'm using
> xlwt) .
>
> plt.savefig('plot.png')
> ws.insert_bitmap('plot.png', 35, 7)
>
> if i run i get this message:
>
> Exception in Tkinter callback
> Traceback (most recent call last):
[snip]
> File "C:\Python26\lib\site-packages\xlwt\Bitmap.py", line 206, in
> _process_bitmap
> raise Exception("bitmap doesn't appear to to be a valid bitmap
> image.")
> Exception: bitmap doesn't appear to to be a valid bitmap image.

"bitmap" == "Windows Bitmap (.BMP) file or contents thereof"

> if i go to the map where i saved the image i CAN open it.

Opening is necessary but not sufficient; xlwt does /only/ .bmp, not .png
etc.
Reply all
Reply to author
Forward
0 new messages