#!/usr/bin/python
# -*- coding: utf-8 -*-


"""
Illustration de la création d'un document feuille de calcul.
"""


__author__ = "Sébastien CHAZALLET"
__copyright__ = "Copyright 2012"
__credits__ = ["Sébastien CHAZALLET", "InsPyration.org", "Éditions ENI"]
__license__ = "GPL"
__version__ = "1.0"
__maintainer__ = "Sébastien CHAZALLET"
__email__ = "sebastien.chazallet@laposte.net"
__status__ = "Production"


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


document = OpenDocumentSpreadsheet()
classic = Style(name="Classique", family="table-cell")
classic.addElement(TextProperties(fontfamily="Arial", fontsize="15pt"))
document.styles.addElement(classic)

important = Style(name="Important", family="table-cell", parentstylename=classic)
important.addElement(TextProperties(fontweight="bold"))
document.automaticstyles.addElement(important)

simplewidth = Style(name="col1", family="table-column")
simplewidth.addElement(TableColumnProperties(columnwidth="2.5cm", breakbefore="auto"))
document.automaticstyles.addElement(simplewidth)
doublewidth = Style(name="col2", family="table-column")
doublewidth.addElement(TableColumnProperties(columnwidth="2.5cm", breakbefore="auto"))
document.automaticstyles.addElement(doublewidth)

content = [[
		P(stylename=classic,text='Case 1 1'),
		P(stylename=classic,text='Case 1 2'),
		P(stylename=classic,text='Case 1 3'),
	], [
		P(stylename=classic,text='Case 2 1'),
		P(stylename=important,text='Case 2 2'),
		P(stylename=classic,text='Case 2 3'),
]]

table = Table(name='test')
table.addElement(TableColumn(numbercolumnsrepeated=1,stylename=simplewidth))
table.addElement(TableColumn(numbercolumnsrepeated=2,stylename=doublewidth))

for l in content:
	r = TableRow()
	for p in l:
		c = TableCell()
		c.addElement(p)
		r.addElement(c)
	table.addElement(r)

document.spreadsheet.addElement(table)

document.save("test.ods")

