Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
I have an xlsm file and have loaded it from a Dataiku folder and changed a few cells using openpyxl. Now I would like to save it back to the Dataiku folder without loosing the macros. Is there a way to make the below work?
file = folder.get_download_stream(my_input_file_path) output = BytesIO() shutil.copyfileobj(file, output) wb = openpyxl.load_workbook(output, read_only=False, keep_vba=True) ws = wb[sheet_name] ws['B2'] = 'something' ws['X6'] = 'something else' wb.save('my_file.xlsm') output.seek(0) with folder.get_writer('my_file.xlsm') as writer: writer.write(output.read())
Hi @Thomas_11 ,
That should work are you seeing a specific issue/error?
Since you are using output.seek(0) you can use read() or getvalue() on the byteIO object.
The get_writer method would work for both remove/local folders.
You can also use upload_stream().
https://knowledge.dataiku.com/latest/code/managed-folders/tutorial-managed-folders.html
with folder.get_writer("filename.xlsm") as writer:
writer.write(output.getvalue())