How to open .xlsx file from binary data?

1,957 views
Skip to first unread message

Shohei Nagata

unread,
Sep 6, 2021, 3:48:54 AM9/6/21
to openpyxl-users
Hi, Team!

I'd like to load .xlsx file stored in Azure Blob Storage with Azure Functions' Python Runtime. I have to input xlsx file as binary data from the Blob Storage. 
However, I couldn't any method to input binary data with openpyxl (load_workbook method can only load a file or file-like object).
Is there any methods to load xlsx file as binary input?

Kind regards,
Shohei

Charlie Clark

unread,
Sep 6, 2021, 7:17:16 AM9/6/21
to openpyxl-users
I think you'll have to write your own code that makes whatever it is available to openpyxl as a file-like object. Presumably, a temporary file or possibly BytesIO. Everything else is outside the scope of the library.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Waldlehne 23
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226

Shohei Nagata

unread,
Sep 6, 2021, 9:42:36 PM9/6/21
to openpyxl-users
Hi Charlie,

Thank you so much for your replying.
I tried BytesIO and the codes started to work well :)
I really appreciate for your advice!

---
from io import BytesIO
import openpyxl

~~

workbook_xml = BytesIO(inputblob)
workbook_xml.seek(0)
wb = openpyxl.load_workbook(workbook_xml)
---

Kind regards,
Shohei
2021年9月6日月曜日 20:17:16 UTC+9 charli...@clark-consulting.eu:
Reply all
Reply to author
Forward
0 new messages