[Calc] Python macro: Save as

Keyboard macros or custom scripts

[Calc] Python macro: Save as

Postby antrrax » Mon Dec 09, 2019 3:20 pm

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?
OpenOffice 4.1.6
antrrax
 
Posts: 6
Joined: Wed Feb 13, 2019 10:50 pm

Re: python macro - save as ? Calc

Postby FJCC » Mon Dec 09, 2019 6:48 pm

Here is a minimal example of doing a Save As in Python.
Code: Select all   Expand viewCollapse view
def SaveAs():
  oDoc = XSCRIPTCONTEXT.getDocument()
  NewURL = "file:///home/fjcc/NewName.ods"
  oDoc.storeToURL(NewURL,())
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7449
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: python macro - save as ? Calc

Postby Ratslinger » Mon Dec 09, 2019 8:31 pm

Please note this was cross posted and also answered here:

https://ask.libreoffice.org/en/question ... e-as-calc/
LibreOffice 6.1.3
OpenOffice 4.0.1
Ubuntu Mate 18.04
Mint 18.3
Ratslinger
 
Posts: 22
Joined: Sun Mar 01, 2015 3:34 am

Re: python macro - save as ? Calc

Postby antrrax » Wed Dec 11, 2019 3:35 pm

FJCC wrote:Here is a minimal example of doing a Save As in Python.



And to save the current file, how do I do?
I tried like this:

Code: Select all   Expand viewCollapse view
def SaveALL():
    oDoc = XSCRIPTCONTEXT.getDocument()
    originalFile= oDoc.URL
    oDoc.storeToURL(originalFile,())

    NewURL = "file:///home/fjcc/NewName.ods"
    oDoc.storeToURL(NewURL,())


If I change the document, the save icon changes from blue to red.
If I apply this macro above, it saves the current file, but libreoffice calc doesn't understand that the file has been saved and the icon is still red and when closing the document manually displays a dialog asking to save or discard changes.

What is the correct way to save the current file in python?
OpenOffice 4.1.6
antrrax
 
Posts: 6
Joined: Wed Feb 13, 2019 10:50 pm

Re: python macro - save as ? Calc

Postby Villeroy » Wed Dec 11, 2019 9:22 pm

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27598
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests