Python, OpenOffice: Programmatically Manipulating spreadsheets

后端 未结 3 1071
闹比i
闹比i 2020-12-10 15:17

I have an spreadsheet-based automated report that needs to be created daily, with some charts, aggregating functions (e.g. SUM and AVERAGE) and formatted cells (Dates, perce

相关标签:
3条回答
  • 2020-12-10 16:02

    You can use PyUNO, a Python library to use UNO API.

    Here is a Python example to do some manipulations in a Calc document.

    0 讨论(0)
  • 2020-12-10 16:03

    Are you looking for this: http://ooopy.sourceforge.net/

    Open Office.org API's accessible from Python?

    Or this? http://api.openoffice.org/

    The OpenOffice.org API Project?

    This may be helpful, also: http://wiki.services.openoffice.org/wiki/Python

    0 讨论(0)
  • 2020-12-10 16:07

    For creating spreadsheets easily: use odslib or for python3: odslib3 … even if the project was last updated over six years ago (2013-07-19) it worked straight out of the box and with just one example viewed. Download the package from the repository for the examples.

    $ pip install odslib
    

    and then a sample spreadsheet could be created like this:

    #!/usr/bin/python
    
    import sys
    import odslib
    
    doc = odslib.ODS()
    
    def writeRow( doc, row, name, power, rating ):
        doc.content.getCell( 0, row).stringValue( name )
        doc.content.getCell( 1, row).stringValue( power )
        doc.content.getCell( 2, row).floatValue( rating )
    
    # the column names
    writeRow( doc, 0, "Name", "Power", "Rating" ) 
    
    # some lines of content
    writeRow( doc, 1, "Mr. Incredible", "Strength", 0.8 ) 
    writeRow( doc, 2, "Elastigirl", "Elasticity", 0.9 ) 
    writeRow( doc, 3, "Frozone", "Ice", 0.7 ) 
    writeRow( doc, 4, "Syndrome", "n/a", 0.3 ) 
    writeRow( doc, 5, "Jack-Jack", "All", 1.0 ) 
    
    doc.save("supers.ods")
    
    0 讨论(0)
提交回复
热议问题