Python macro - save as ? Calc

I have a button in a .ODS spreadsheet with a python macro that modifies some cells.
I need to save this modified .ODS file in another directory and under another name via python.

how to do this?

Hello,

Please although there is no problem in cross posting, please note that you have done this with a link in each post. This will help avoid duplicate efforts.

Also posted here → python macro - save as ? Calc

Try:

path = uno.systemPathToFileUrl('/home/USER/PATH/new_name.ods')
doc.storeAsURL(path, ())

More information about documents:
https://wiki.documentfoundation.org/Macros/Python_Guide/Documents

EDIT:

I test and work fine:

path = uno.systemPathToFileUrl('/home/mau/origin.ods')
desktop = XSCRIPTCONTEXT.getDesktop()
doc = desktop.loadComponentFromURL(path, '_blank', 0, ())
cell = doc.CurrentController.Selection
cell.String = 'New File'
path = uno.systemPathToFileUrl('/home/mau/new_file.ods')
doc.storeAsURL(path, ())
1 Like

This did not work as it is saving only the original file without modification.
I have a file my_template.ODS, the python macro modifies some cells and wanted to save it in another folder.

As shown above you are saving the original my_template.ODS file without any changes.

I could use the code above to first save my_template.ODS in the current folder and then repeat the code to save in another folder with another name.
But is there another solution?

How to open your file?

my_template.ODS, it’s not a template, but, you can open like template with arguments: “AsTemplate” = True

storeAsURL, work fine if; it’s a new document or open document as save with other name.

I did a cleanup on my macro code and now it worked fine.
There was probably something disturbing the correct file creation

Thanks a lot for the help