[CentralOH] Personal Budget with LibreOffice and Python

Joshua Kramer joskra42.list at gmail.com
Fri Sep 21 04:38:47 CEST 2012


Howdy Folks...

I thought I'd share this spreadsheet that I use to do monthly
budgeting.  I'm sharing with this group because it is a good example
of how to use Python to script LibreOffice activities.  Eventually I
would like to give a talk about this (and other tips & tricks of
Python-LO integration) at one of the meetings, but for now here's what
I have.

When you open the workbook, there is one sheet called "Builder".  When
you run the embedded Python script, it does the following:

for Week in (list of bi-weekly pay periods):
    Copy "Builder" to a new sheet
    Label the new sheet appropriately
    Join the "excess from previous pay period" cell to the "excess"
cell of the previous pay period

So at the end of the run you'll have 26 worksheets, one for each pay period.

To use this:

1. Make sure you can run macros.  (Tools -> Options -> Security ->
Macro Security)
2. Open the workbook.
3. Enter your budget information in the "Planned" column (B).  Note
that each worksheet covers two weeks - so after the macro is run,
you'll have to go in and adjust which worksheets should contain the
various items, since most items are monthly.
4. Select Tools -> Macros -> Run Macro.  When the Selector pops up,
select the library "BudgetTemplate.ods".
5. Click on the "Main_RunMe" macro, and click Run.
6. After all of the worksheets have appeared, adjust accordingly.
Note that the three green income items at the top are part of a group
and can be edited if you want; they're summed up to the "Total Income"
cell.  Also note that the "Total Excess" cell on one worksheet is
linked to the "Excess from Previous Pay" on the next sheet.  That way
you can see how much money you'll have left at the end of the year if
you follow your budget.
7. As you pay your bills, you may find it helpful to enter amounts in
the "Actual" column.

To investigate or hack the Python script:

1. Create a temporary directory and unzip the .ods file into that directory.
2. In the temporary directory, there will be a path named
Scripts/python.  The Python script is in that directory.  It is fairly
well commented.

If you add another module, or if your editor makes backup~ files, and
you try to simply zip the temp directory back up into an .ods file,
then LibreOffice will report the spreadsheet as corrupt.  You can add
additional modules by adding the .py files, and then editing the
META-INF/manifest.xml file to add a file-entry node containing the
information about your file.

Any suggestions for improvement are welcome!

Cheers,
-JK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BudgetTemplate.ods
Type: application/vnd.oasis.opendocument.spreadsheet
Size: 22781 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/centraloh/attachments/20120920/793f8ac1/attachment-0001.ods>


More information about the CentralOH mailing list