Help with Python?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Help with Python?

Post by Valen Banpaia »

I can't get python to allow me to create anything in it. I Tool-Macros-Organize_Macros-Python..., but when it opens it doesn't have a module accessible to edit. If you know what I should do to fix this, help me, please and thank you.
OOo 3.2.1 on MS Windows Vista Home Premium
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Help with Python?

Post by Villeroy »

Simply use the same editor you use to write your Python programs with. Make shure that the code is saved with Unix line feeds.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
FJCC
Moderator
Posts: 9285
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with Python?

Post by FJCC »

To expand a bit on Villeroy's reply - after you write the python code using a text editor, you should save it in a folder like

C:\Documents and Settings\username\Application Data\OpenOffice\3\user\Scripts\python

All of those folders should already exist except possibly the last one named python. Your path may be a little different, since you use Vista. Files saved in that python folder will appear under My Macros when you select Tool-Macros-Organize_Macros-Python
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: Help with Python?

Post by Valen Banpaia »

I tried what you said, and it said file not found. So, I tried opening the OOo Pythons and it said there was an error in invoking the module file.
OOo 3.2.1 on MS Windows Vista Home Premium
FJCC
Moderator
Posts: 9285
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with Python?

Post by FJCC »

If I understand you correctly you tried to run the python.exe file at

C:\Program Files\Sun\OpenOffice 3\program

(or the Vista equivalent of that) and got an error. If that is true, then I suggest a reinstall of OpenOffice.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: Help with Python?

Post by Valen Banpaia »

If I reinstall will I lose my OOo documents and previous functions?
OOo 3.2.1 on MS Windows Vista Home Premium
FJCC
Moderator
Posts: 9285
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with Python?

Post by FJCC »

You will definitely not lose your documents. You should also not lose your functions, though I am not absolutely certain that the re-installation process will automatically save the them. I am almost certain it will, but I would hate to steer you wrong. The safest thing would be to save a copy of your user profile in a personal directory, e.g. your desktop, just in case. The user profile is explained in this tutorial User Profile
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: Help with Python?

Post by Valen Banpaia »

Okay, I reinstalled OOo and, except for altered defaults, it didn't change anything. What do I do now?
OOo 3.2.1 on MS Windows Vista Home Premium
FJCC
Moderator
Posts: 9285
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with Python?

Post by FJCC »

I would open a blank Writer document and select Tools -> Macros -> Organize Macros -> Python. Expand the OpenOffice Macros tree and then expand the TableSample folder. Click on the createTable module and then choose Run. A new document should appear with the first line "The first line in the newly created text document." and a table. If that works, then your Python is now fine
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Valen Banpaia
Posts: 10
Joined: Mon Jun 22, 2009 7:37 am

Re: Help with Python?

Post by Valen Banpaia »

When I do that, will I just need to type the formula in the first line? If so, please reply in my numerology calculator topic, thank you.
OOo 3.2.1 on MS Windows Vista Home Premium
FJCC
Moderator
Posts: 9285
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Help with Python?

Post by FJCC »

Setting this up takes a couple of steps, at least for me, because I don't know how to set up a python macro to be called as a function. I can call the python macro through a Basic function. It's late my time, so I'll have to wait until tomorrow to post the full answer in the other thread.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Help with Python?

Post by Villeroy »

Create your functions, so they can be used with any program regardless of any office suite.

Spreadsheet functions can be written directly in Basic or in any other language. In the first case they are organized and copied as Basic macros, in the latter case they need to be wrapped in an extension and appear just like the built-in functions in the formula wizard, optional with localized names, descriptions and help file. Basic functions are easy to implement, extension packages are easy to distribute and easy to use.
http://www.oooforum.org/forum/viewtopic ... 671#312671 contains an example how to use a well known Python function (Soundex) in a spreadsheet. It is called through another function written in Basic, so you don't have to build an extension.
=SOUNDEX("some text") calls the Basic function which then invokes the Python function and returns the result of the Python function as it's own result back to the sheet.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply