pyexcel/pyexcel-xls

XLS to BytesIO response stream created on the fly

Closed this issue · 1 comments

I'm trying to create response stream with XLS file created on the fly, but only first call to save_to_memory is shown in the downloaded file

The result of the following example is XLS file with only one row of data (instead of 4):

import io
import pyexcel as pe
from aiohttp import web

async def get(request):
  response = web.StreamResponse(headers={'Content-Disposition': 'inline; filename="myfile.xls"'})
  await response.prepare(request)
  response.content_type = 'multipart/x-mixed-replace;boundary=ffserver'
  data = [1,2,3,4]
  mem = io.BytesIO()
  sheet = pe.Sheet(name='ids', colnames=['id'])

  try:
      for id in data:
         sheet.extend_rows([id])
         mem = sheet.save_to_memory("xls", mem)
         await response.write(mem.read())
  finally:
      await response.write_eof()

Is it even possible doing so with this file format?

Thanks

chfw commented

answered in pyexcel repo.