finally successful in ods with python, just one help needed.
Krishnakant
hackingkk at gmail.com
Sat Mar 14 17:10:52 EDT 2009
Hi David,
based on your code snippid I added a couple of lines to actually center
align text in the merged cell in first row.
Please note in the following code that I have added ParagraphProperties
in the imports and created one style with textalign="center" as an
attribute.
*** code follows ***
import sys
from odf.opendocument import OpenDocumentSpreadsheet
from odf.style import Style, TableColumnProperties, ParagraphProperties
from odf.table import Table, TableRow, TableColumn, TableCell,
CoveredTableCell
from odf.text import P
class makeods:
def make_ods(self):
ods = OpenDocumentSpreadsheet()
col = Style(name='col', family='table-column')
col.addElement(TableColumnProperties(columnwidth='1in'))
tablecontents = Style(name="Table Contents", family="paragraph")
tablecontents.addElement(ParagraphProperties(textalign="center"))
table = Table()
table.addElement(TableColumn(numbercolumnsrepeated=3,
stylename=col))
ods.spreadsheet.addElement(table)
# Add first row with cell spanning columns A-C
tr = TableRow()
table.addElement(tr)
tc = TableCell(numbercolumnsspanned=3)
tc.addElement(P(stylename=tablecontents, text="ABC1"))
tr.addElement(tc)
# Uncomment this to more accurately match native file
##tc = CoveredTableCell(numbercolumnsrepeated=2)
##tr.addElement(tc)
# Add two more rows with non-spanning cells
for r in (2,3):
tr = TableRow()
table.addElement(tr)
for c in ('A','B','C'):
tc = TableCell()
tc.addElement(P(text='%s%d' % (c, r)))
tr.addElement(tc)
ods.save("ods-test.ods")
m = makeods()
m.make_ods()
Still the text in the cell is not centered.
happy hacking.
Krishnakant.
More information about the Python-list
mailing list