在GAE中的Excel文件(xlwt)中插入位图图像 [英] Insert bitmap image in Excel file(xlwt) in GAE

查看:1609
本文介绍了在GAE中的Excel文件(xlwt)中插入位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Excel文件中插入位图图像(使用xlwt创建)。

错误:

  Traceback(最近一次调用最后一次):
文件C:\程序文件\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py ,第701行,在__call__
handler.get(* groups)
文件C:\apps\test.py,第44行,获取
ws0.insert_bitmap('images /logo.gif',2,2)
文件C:\apps\xlwt\Worksheet.py,第1034行,位于insert_bitmap
bmp = Bitmap.ImDataBmpRecord(filename)
文件C:\apps\xlwt\Bitmap.py,行255,位于__init__
self.width,self.height,self.size,data = _process_bitmap(filename)
文件C:\apps\xlwt\Bitmap.py,第195行,位于_process_bitmap
中fh =文件(位图,rb)
文件C:\程序文件\ Google_\\google_appengine\google\appengine\tools\dev_appserver_import_hook.py,第578行,在__init __
提高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)

请让我知道如果有任何解决方法吗?



干杯! ,

NN

解决方案

我确定这个项目很久以后就完成了,但请查看xlsxwriter



http://xlsxwriter.readthedocs .org / en / latest / example_images.html b
$ b 插入图片比xlwt好多了,支持jpeg和png文件,不仅仅是bmp p>


如果您需要在一次插入中抵消并缩放图片:


worksheet.insert_image('B5','/python/reports/garmentspreadsheet/Images/Garments/6702RD-WH.jpg',{'x_offset':2,'y_offset':2,'x_scale' :0.5,'y_scale':0.5})


偏移量以像素为单位



没有xlsxwriter


  • pip安装xlsxwriter

  • ul>

    没有点子?它就像easy_install


    • centos / redhat

      yum install python- pip

      yum install pip


    • debian

      apt-get安装pip



    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

    解决方案

    I'm sure this project is long since done, but check out xlsxwriter

    http://xlsxwriter.readthedocs.org/en/latest/example_images.html

    It's a lot better at inserting images than xlwt, supports jpegs and png files, not just bmp

    if you need to offset -and- scale an image in one insert:

    worksheet.insert_image('B5', '/python/reports/garmentspreadsheet/Images/Garments/6702RD-WH.jpg', {'x_offset': 2, 'y_offset': 2, 'x_scale': 0.5, 'y_scale': 0.5})

    offsets are in pixels

    Don't have xlsxwriter

    • pip install xlsxwriter

    don't have pip? it's like easy_install

    • centos/redhat

      yum install python-pip or yum install pip

    • debian

      apt-get install pip

    这篇关于在GAE中的Excel文件(xlwt)中插入位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆