开发者

Excel file writing using xlwt+Google app engine - Getting IOError: invalid mode: wb

In my application i'm trying to write the data to excel file using xlwt API. When i run the GAE app, i got following error . Please help me to fix this bug.

Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 700, in __call__
    handler.get(*groups)
  File "C:\Users\stocklist\temp.py", line 39, in get
    wb.save('example.xls')
  File "C:\Users\stocklist\xlwt\Workbook.py", line 634, in save
    doc.save(filename, self.get_biff_data())
  File "C开发者_如何学JAVA:\Users\stocklist\xlwt\CompoundDoc.py", line 507, in save
    f = open(file_name_or_filelike_obj, 'wb')
  File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1427, in __init__
    raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: wb

Source code:

class MainHandler(webapp.RequestHandler):
    def get(self):      

        font0 = xlwt.Font()
        font0.name = 'Times New Roman'
        font0.colour_index = 2
        font0.bold = True

        style0 = xlwt.XFStyle()
        style0.font = font0

        style1 = xlwt.XFStyle()
        style1.num_format_str = 'D-MMM-YY'

        wb = xlwt.Workbook()
        ws = wb.add_sheet('A Test Sheet')

        ws.write(0, 0, 'Test', style0)
        ws.write(1, 0, datetime.now(), style1)
        ws.write(2, 0, 1)
        ws.write(2, 1, 1)
        ws.write(2, 2, xlwt.Formula("A3+B3"))

        wb.save('example.xls')


You can't write files to the filesystem on App Engine. Instead, serialize it and save it to the datastore or blobstore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜