finally successful in ods with python, just one help needed.

David Bolen at
Sat Mar 14 18:46:37 CET 2009

Krishnakant <hackingkk at> writes:

> However when I apply the same elements and attributes to the one I am
> creating with odfpy, I get "attribute not allowed " errors.
> If some one is interested to look at the code, please let me know, I can
> send an attachment off the list so that others are not forced to
> download some thing they are not concerned about.

I just tried this myself and the following creates a 3x3 spreadsheet
with the first row spanning all three columns (no special formatting
like centering or anything), using odf2py 0.8:

    import sys

    from odf.opendocument import OpenDocumentSpreadsheet
    from import Style, TableColumnProperties
    from odf.table import Table, TableRow, TableColumn, \
                          TableCell, CoveredTableCell
    from odf.text import P

    def make_ods():
        ods = OpenDocumentSpreadsheet()

        col = Style(name='col', family='table-column')

        table = Table()
        table.addElement(TableColumn(numbercolumnsrepeated=3, stylename=col))

        # Add first row with cell spanning columns A-C
        tr = TableRow()
        tc = TableCell(numbercolumnsspanned=3)
        # Uncomment this to more accurately match native file
        ##tc = CoveredTableCell(numbercolumnsrepeated=2)

        # Add two more rows with non-spanning cells
        for r in (2,3):
            tr = TableRow()
            for c in ('A','B','C'):
                tc = TableCell()
                tc.addElement(P(text='%s%d' % (c, r)))

Maybe that will give you a hint as to what is happening in your case.

Note that it appears creating such a spreadsheet directly in Calc also
adds covered table cells for those cells beneath the spanned cell, but
Calc loads a file fine without those and still lets you later split
the merge and edit the underlying cells.  So I'm not sure how required
that is as opposed to just how Calc manages its own internal structure.

-- David

More information about the Python-list mailing list