0

I have the working knowledge for uploading/creating objects in google cloud storage, but when trying to do same with Workbook created using xlxswriter it throws exception and won't allow to create object. Tried converting workbook to bytes/string as it is supported by cloud storage for upload.

Below code was used for creating a workbook in required format

workbook = xlsxwriter.Workbook('SampleDownload.xlsx')
worksheet = workbook.add_worksheet("xyz")
worksheet.freeze_panes(1, 1)
formater = workbook.add_format()
formater.set_bold()
formater.set_bg_color('red')
---code block for adding data---
workbook.close()

Now while trying to upload workbook on cloud storage using blob (upload_from_file) method, it thorws exception as 'Workbook' object has no attribute 'tell'.

So to overcome this I tried converting workbook to bytes as bytes are uploadable on google cloud storage using io.BytesIO(workbook) but it throws exception as TypeError: a bytes-like object is required, not 'Workbook'.

  • Using your code I generated a xlsx file. I used `upload_from_file()` to upload it to GCS and it works fine for me. What version of `google-cloud-storage` are you using? – Ricco D Oct 04 '22 at 00:10
  • google-cloud-storage version used is 2.4.0 but while uploading it throws exception for me. – Siddharth Sancheti Oct 05 '22 at 07:24

0 Answers0