What Python code opens a specific Calc file?

Running Libreoffice 6.0.4.2 on Windows 7 Pro

I have searched all over for an answer as to how to open an existing Calc file using Python. I have read Christopher Bourez’s blog . He shows how to launch Calc so it opens on the desktop. Using his code I can launch the Python shell and connect to LibreOffice. He does not show how to open a specific Calc file.

I want to export 50 Calc files to csv files . Doing this manually takes a long time.

I am trying to understand how to open a specific Calc file . All my Calc files are in the C:\Document folder.

My question: Once Python is connected to Libreoffice , what commands are needed to open a specific Calc file stored in C:\document folder?

I want to export 50 Calc files to csv files . Doing this manually takes a long time.

With Unoconv you can do that on a POSIX shell like this:

unoconv -f csv the-folder-with-the-50-calc-files/*.ods

(I’m not familiar enough with Windows shell to know if that works, but from what I can read, it seams to support globbing, e.g. the *. Otherwise Busybox for Windows inculdes a POSIX shell. Someone who knows Windows may have more of a clue here.)

Using his code I can launch the Python shell and connect to LibreOffice. He does not show how to open a specific Calc file.

If it for some reason is a requirement for you to use Python, give these PyUNO examples a look. It looks like it would be fairly simple to add CSV export to the ooextract.py example which extracts plaintext, HTML or PDF.

ctx = uno.getComponentContext()
asmgr = ctx.ServiceManager
thepathtodoc = "C:\myfile.ods" #"/home/foo/Documents/file.odt"
thedocurl = uno.systemPathToFileUrl(thepathtodoc)
adesktop = asmgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
somefile = adesktop.loadComponentFromURL(thedocurl,"_blank",0,array())