write a xlsm file to a Dataiku folder
Thomas_11
Registered Posts: 1 ✭
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())
Tagged:
Answers
-
Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,226 Dataiker
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.htmlwith folder.get_writer("filename.xlsm") as writer: writer.write(output.getvalue())