0

There's a excel file with stream format.


from io import BytesIO
from openpyxl.workbook import Workbook

stream_file = BytesIO()
wb = Workbook(write_only=True)
ws = wb.create_sheet()
...
wb.save(stream_file)
stream_file.seek(0)

Update

size-of-an-open-file-object

I tried with one of answer above

print(os.fstat(stream_file.fileno()).st_size)

then got error

    print(os.fstat(stream_file.fileno()).st_size)
io.UnsupportedOperation: fileno

And below trial successed

stream_file.seek(0, 2)
print(stream_file.tell())
stream_file.seek(0)

Is there other way to get the size of this stream file ?

jia Jimmy
  • 1,563
  • 13
  • 34
  • "Is there other way to get the size of this stream file ?" Why not use the ``stream.tell`` approach? It's used in the accepted and highest-voted answers of the dupe for a reason. – MisterMiyagi Jan 13 '22 at 06:30

0 Answers0