【问题标题】:Excel file writing using xlwt+Google app engine - Getting IOError: invalid mode: wb使用 xlwt+Google 应用引擎写入 Excel 文件 - 获取 IOError:无效模式:wb
【发布时间】:2011-10-05 06:49:47
【问题描述】:

在我的应用程序中,我正在尝试使用 xlwt API 将数据写入 excel 文件。当我运行 GAE 应用程序时,出现以下错误。请帮我修复这个错误。

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:\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

源代码:

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')

【问题讨论】:

    标签: python google-app-engine xlwt file-writing


    【解决方案1】:

    您无法将文件写入 App Engine 上的文件系统。相反,将其序列化并将其保存到数据存储或 blobstore。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      相关资源
      最近更新 更多