<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=Create_an_OpenOffice_SpreadSheet</id>
	<title>Create an OpenOffice SpreadSheet - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dabo.leafe.com/index.php?action=history&amp;feed=atom&amp;title=Create_an_OpenOffice_SpreadSheet"/>
	<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=Create_an_OpenOffice_SpreadSheet&amp;action=history"/>
	<updated>2026-11-21T23:40:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://wiki.dabo.leafe.com/index.php?title=Create_an_OpenOffice_SpreadSheet&amp;diff=4183&amp;oldid=prev</id>
		<title>Ed: Created page with &quot;Reporting from Dabo is normally done by using &lt;code&gt;reportWriter.py&lt;/code&gt;. It works very well for document type reports, but often our clients require a spreadsheet. Since my...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.dabo.leafe.com/index.php?title=Create_an_OpenOffice_SpreadSheet&amp;diff=4183&amp;oldid=prev"/>
		<updated>2020-05-17T14:34:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Reporting from Dabo is normally done by using &amp;lt;code&amp;gt;reportWriter.py&amp;lt;/code&amp;gt;. It works very well for document type reports, but often our clients require a spreadsheet. Since my...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Reporting from Dabo is normally done by using &amp;lt;code&amp;gt;reportWriter.py&amp;lt;/code&amp;gt;. It works very well for document type reports, but often our clients require a spreadsheet. Since my clients are using &amp;#039;&amp;#039;&amp;#039;OpenOffice&amp;#039;&amp;#039;&amp;#039; I needed a way to create spreadsheet from Dabo. Turns out that creating an OpenOffice spreadsheet from Dabo is very easy.&lt;br /&gt;
&lt;br /&gt;
Turns out a fellow Pythonian &amp;#039;&amp;#039;&amp;#039;Joseph Colton&amp;#039;&amp;#039;&amp;#039; has written a module to create both OpenOffice spreadsheets and documents. It does not interface with OpenOffice like a COM object in the MS windows worldut creates a file that OpenOffice can read. It can be download from http://ooolib.sourceforge.net&lt;br /&gt;
&lt;br /&gt;
I have created a Dabo self contained example. For you MS windows users you will have to change the path and the OpenOffice executable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
import os&lt;br /&gt;
import ooolib&lt;br /&gt;
#http://ooolib.sourceforge.net&lt;br /&gt;
import dabo&lt;br /&gt;
import dabo&lt;br /&gt;
dabo.ui.loadUI(&amp;quot;wx&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# app:&lt;br /&gt;
app = dabo.dApp(MainFormClass=None)&lt;br /&gt;
app.setup()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# db:&lt;br /&gt;
con = dabo.db.dConnection(DbType=&amp;#039;sqlite&amp;#039;, Database=&amp;#039;:memory:&amp;#039;)&lt;br /&gt;
cur = con.getDaboCursor()&lt;br /&gt;
cur.execute(&amp;quot;create table customers (id INTEGER PRIMARY KEY, name CHAR, valid INT)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Paul&amp;#039;, 0)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;John&amp;#039;, 1)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Larry&amp;#039;, 2)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Ed&amp;#039;, 3)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Viola&amp;#039;, 4)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Bill&amp;#039;, 5)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Pascale&amp;#039;, 6)&amp;quot;)&lt;br /&gt;
cur.execute(&amp;quot;insert into customers (name, valid) values (&amp;#039;Donna&amp;#039;, 7)&amp;quot;)&lt;br /&gt;
cur.flush()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# biz:&lt;br /&gt;
biz = dabo.biz.dBizobj(con)&lt;br /&gt;
biz.DataSource = &amp;quot;customers&amp;quot;&lt;br /&gt;
biz.KeyField = &amp;quot;id&amp;quot;&lt;br /&gt;
biz.UserSQL = &amp;quot;select id, name, valid from customers&amp;quot;&lt;br /&gt;
biz.DataStructure = (&lt;br /&gt;
        # (field_alias, field_type, pk, table_name, field_name, field_scale)&lt;br /&gt;
        (&amp;quot;id&amp;quot;, &amp;quot;I&amp;quot;, True, &amp;quot;customers&amp;quot;, &amp;quot;id&amp;quot;),&lt;br /&gt;
        (&amp;quot;name&amp;quot;, &amp;quot;C&amp;quot;, False, &amp;quot;customers&amp;quot;, &amp;quot;name&amp;quot;),&lt;br /&gt;
        (&amp;quot;valid&amp;quot;, &amp;quot;B&amp;quot;, False, &amp;quot;customers&amp;quot;, &amp;quot;valid&amp;quot;))&lt;br /&gt;
&lt;br /&gt;
biz.requery()&lt;br /&gt;
#the UI&lt;br /&gt;
frm = dabo.ui.dForm()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def btnCreate(evt):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot; Set values.  The values are set in column, row order, but the values are&lt;br /&gt;
    not in the traditional &amp;quot;A5&amp;quot; style format.  Instead we require two integers.&lt;br /&gt;
    set_cell_value(col, row, datatype, value)&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    doc = ooolib.Calc()&lt;br /&gt;
    ds=biz.getDataSet()&lt;br /&gt;
    row_num=1  ## start with 1 = A1&lt;br /&gt;
    for row in ds:&lt;br /&gt;
        col_num=1&lt;br /&gt;
        for cols in row.keys():&lt;br /&gt;
            if type(row[cols]) is bool:&lt;br /&gt;
                columntype=&amp;#039;bool&amp;#039;&lt;br /&gt;
            elif type(row[cols]) is int:&lt;br /&gt;
                columntype=&amp;#039;float&amp;#039;&lt;br /&gt;
            elif type(row[cols]) is unicode:&lt;br /&gt;
                columntype=&amp;#039;string&amp;#039;&lt;br /&gt;
            # OK let&amp;#039;s write out the data to spreadsheet&lt;br /&gt;
            doc.set_cell_value(col_num, row_num, columntype, row[cols])&lt;br /&gt;
            col_num=col_num+1&lt;br /&gt;
            row_num=row_num+1&lt;br /&gt;
&lt;br /&gt;
    # Save the document to the file you want to create.&lt;br /&gt;
    # You need to change the path to match your environment&lt;br /&gt;
    doc.save(&amp;quot;/home/johnf/dabo-example01.ods&amp;quot;)&lt;br /&gt;
    #below will allow me to open the spreadsheet using OpenOffice (linux)&lt;br /&gt;
    # I believe windows users need &amp;#039;scalc.exe&amp;#039;&lt;br /&gt;
    os.popen2(&amp;#039;/usr/bin/oocalc /home/johnf/dabo-example01.ods&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
theButton = dabo.ui.dButton(frm,Caption=&amp;quot;Push Me&amp;quot;,OnHit=btnCreate)&lt;br /&gt;
frm.Sizer.append1x(theButton)&lt;br /&gt;
&lt;br /&gt;
#run it&lt;br /&gt;
frm.show()&lt;br /&gt;
app.start()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ed</name></author>
	</entry>
</feed>