我需要在 Excel 文件中插入位图图像(使用 xlwt 创建)。我尝试使用 insert_bimap() 方法插入,但它返回 IO 错误。
错误:
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'
代码:
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)
请让我知道是否有任何解决方法?
干杯! ,
神经网络