summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Rogers <f4nt@f4ntasmic.com>2011-05-14 16:13:17 -0500
committerMark Rogers <f4nt@f4ntasmic.com>2011-05-14 16:13:17 -0500
commit420dd36ab8c4fa7a3f75b8da80ffc2effdf0029e (patch)
tree000454f244f158e8c956b2bc1bab8bc5435de9f8
parent9a05770899a5864e72727830da71a23b7203d050 (diff)
downloadtablib-420dd36ab8c4fa7a3f75b8da80ffc2effdf0029e.tar.gz
Tidied up a bit, renamed _odf to _ods like it should have been. Bold not working yet :(
-rw-r--r--tablib/core.py2
-rw-r--r--tablib/formats/__init__.py4
-rw-r--r--tablib/formats/_ods.py (renamed from tablib/formats/_odf.py)52
-rwxr-xr-xtest_tablib.py2
4 files changed, 26 insertions, 34 deletions
diff --git a/tablib/core.py b/tablib/core.py
index e8e17ce..678e515 100644
--- a/tablib/core.py
+++ b/tablib/core.py
@@ -402,7 +402,7 @@ class Dataset(object):
pass
@property
- def odf():
+ def ods():
"""An Excel Spreadsheet representation of the :class:`Dataset` object, with :ref:`separators`. Cannot be set.
.. admonition:: Binary Warning
diff --git a/tablib/formats/__init__.py b/tablib/formats/__init__.py
index 58199a3..5fdf279 100644
--- a/tablib/formats/__init__.py
+++ b/tablib/formats/__init__.py
@@ -10,6 +10,6 @@ from . import _yaml as yaml
from . import _tsv as tsv
from . import _html as html
from . import _xlsx as xlsx
-from . import _odf as odf
+from . import _ods as ods
-available = (json, xls, yaml, csv, tsv, html, xlsx, odf)
+available = (json, xls, yaml, csv, tsv, html, xlsx, ods)
diff --git a/tablib/formats/_odf.py b/tablib/formats/_ods.py
index 4dafab4..d4520c7 100644
--- a/tablib/formats/_odf.py
+++ b/tablib/formats/_ods.py
@@ -11,23 +11,26 @@ if sys.version_info[0] > 2:
else:
from cStringIO import StringIO as BytesIO
-from tablib.compat import openpyxl
-
-from odf.opendocument import OpenDocumentSpreadsheet
-from odf.style import Style, TextProperties, TableColumnProperties, Map
-from odf.number import NumberStyle, CurrencyStyle, CurrencySymbol, Number, Text
-from odf.text import P
-from odf.table import Table, TableColumn, TableRow, TableCell
+from tablib.packages.odf.opendocument import OpenDocumentSpreadsheet
+from tablib.packages.odf.style import Style, TextProperties, TableColumnProperties, Map
+from tablib.packages.odf.number import NumberStyle, CurrencyStyle, CurrencySymbol, Number, Text
+from tablib.packages.odf.text import P
+from tablib.packages.odf.table import Table, TableColumn, TableRow, TableCell
from tablib.compat import unicode
-title = 'odf'
-extentions = ('odf',)
+title = 'ods'
+extentions = ('ods',)
+
+bold = Style(name='Bold', family="text")
+bold.addElement(TextProperties(fontweight="bold"))
def export_set(dataset):
"""Returns ODF representation of Dataset."""
wb = OpenDocumentSpreadsheet()
+ wb.automaticstyles.addElement(bold)
+
ws = Table(name=dataset.title if dataset.title else 'Tablib Dataset')
wb.spreadsheet.addElement(ws)
dset_sheet(dataset, ws)
@@ -41,6 +44,8 @@ def export_book(databook):
"""Returns ODF representation of DataBook."""
wb = OpenDocumentSpreadsheet()
+ wb.automaticstyles.addElement(bold)
+
for i, dset in enumerate(databook._datasets):
ws = Table(name=dset.title if dset.title else 'Sheet%s' % (i))
wb.spreadsheet.addElement(ws)
@@ -62,32 +67,24 @@ def dset_sheet(dataset, ws):
for i, row in enumerate(_package):
row_number = i + 1
- odf_row = TableRow()
+ odf_row = TableRow(stylename=bold)
for j, col in enumerate(row):
ws.addElement(TableColumn())
- #col_idx = get_column_letter(j + 1)
# bold headers
if (row_number == 1) and dataset.headers:
+ odf_row.setAttribute('stylename', bold)
ws.addElement(odf_row)
cell = TableCell()
- cell.addElement(P(text=col))
+ cell.addElement(P(stylename="Bold", text=unicode(col, errors='ignore')))
odf_row.addElement(cell)
- #style = ws.get_style('%s%s' % (col_idx, row_number))
- #style.font.bold = True
- #ws.freeze_panes = '%s%s' % (col_idx, row_number)
-
# bold separators
elif len(row) < dataset.width:
ws.addElement(odf_row)
cell = TableCell()
- cell.addElement(P(text=col))
+ cell.addElement(P(text=unicode(col, errors='ignore')))
odf_row.addElement(cell)
- #ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
- # '%s' % col, errors='ignore')
- #style = ws.get_style('%s%s' % (col_idx, row_number))
- #style.font.bold = True
# wrap the rest
else:
@@ -95,24 +92,17 @@ def dset_sheet(dataset, ws):
if '\n' in col:
ws.addElement(odf_row)
cell = TableCell()
- cell.addElement(P(text=col))
+ cell.addElement(P(text=unicode(col, errors='ignore')))
odf_row.addElement(cell)
- #ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
- # '%s' % col, errors='ignore')
- #style = ws.get_style('%s%s' % (col_idx, row_number))
- #style.alignment.wrap_text
else:
ws.addElement(odf_row)
cell = TableCell()
- cell.addElement(P(text=col))
+ cell.addElement(P(text=unicode(col, errors='ignore')))
odf_row.addElement(cell)
- #ws.cell('%s%s'%(col_idx, row_number)).value = unicode(
- # '%s' % col, errors='ignore')
except TypeError:
ws.addElement(odf_row)
cell = TableCell()
- cell.addElement(P(text=col))
+ cell.addElement(P(text=unicode(col, errors='ignore')))
odf_row.addElement(cell)
- #ws.cell('%s%s'%(col_idx, row_number)).value = unicode(col)
diff --git a/test_tablib.py b/test_tablib.py
index 474323a..5715eb0 100755
--- a/test_tablib.py
+++ b/test_tablib.py
@@ -223,6 +223,7 @@ class TablibTestCase(unittest.TestCase):
data.tsv
data.xls
data.xlsx
+ data.ods
data.html
@@ -236,6 +237,7 @@ class TablibTestCase(unittest.TestCase):
book.yaml
book.xls
book.xlsx
+ book.ods
def test_json_import_set(self):