def test_nested_formula(self):
     lrows = launder_through_lo([["Formula",  # A1
                                  1,  # B1
                                  2,  # C1
                                  3,  # D1
                                  ods.Formula("IF(C1=2;MIN(B1:D1);MAX(B1:D1))"),  # E1
                                  ods.Formula("IF(C1=3;MIN(B1:D1);MAX(B1:D1))")]])  # F1
     self.assertEqual(lrows, [["Formula","1","2","3","1","3"]])
 def test_formula(self):
     lrows = launder_through_lo([["Formula",  # A1
                                  1,  # B1
                                  2,  # C1
                                  3,  # D1
                                  ods.Formula("IF(C1=2;B1;C1)"),  # E1
                                      ods.Formula("SUM(B1:D1)")]])  # F1
     self.assertEqual(lrows, [["Formula","1","2","3","1","6"]])
Exemple #3
0
 def test_single_sheet(self):
     f = io.BytesIO()
     with ods.writer(f) as odsfile:
         odsfile.writerow(["String", "ABCDEF123456", "123456"])
         # Lose the 2L below if you want to run this example code on Python 3, Python 3 has no long type.
         odsfile.writerow(["Float", 1, 123, 123.123, decimal.Decimal("10.321")])
         odsfile.writerow(["Date/DateTime", datetime.datetime.now(), datetime.date(1989, 11, 9)])
         odsfile.writerow(["Time", datetime.time(13, 37), datetime.time(16, 17, 18)])
         odsfile.writerow(["Bool", True, False, True])
         odsfile.writerow(["Formula", 1, 2, 3, ods.Formula("IF(A1=2,B1,C1)")])
     val = f.getvalue()
     self.assertGreater(len(val), 0)
Exemple #4
0
 def setUp(self):
     self.rows = [["String", "ABCDEF123456", "123456"],
                  ["Float", 1, 123, 123.123,
                   decimal.Decimal("10.321")],
                  [
                      "Date/DateTime",
                      datetime.datetime.now(),
                      datetime.date(1989, 11, 9)
                  ],
                  [
                      "Time",
                      datetime.time(13, 37),
                      datetime.time(16, 17, 18)
                  ], ["Bool", True, False, True],
                  ["Formula", 1, 2, 3,
                   ods.Formula("IF(A1=2,B1,C1)")]]
#!/usr/bin/env python

'''
# PLACEHOLDER CODE
# copy pasted straight from the example at https://github.com/mmulqueen/odswriter

TODO:
  * Parse datapackage.json and read the JSON table schema
  * Lint and store rows
'''

import datetime
import decimal
import odswriter as ods

with ods.writer(open("test.ods","wb")) as odsfile:
    odsfile.writerow(["String", "ABCDEF123456", "123456"])
    # Lose the 2L below if you want to run this example code on Python 3, Python 3 has no long type.
    odsfile.writerow(["Float", 1, 123, 123.123, 2L, decimal.Decimal("10.321")])
    odsfile.writerow(["Date/DateTime", datetime.datetime.now(), datetime.date(1989,11,9)])
    odsfile.writerow(["Time",datetime.time(13,37),datetime.time(16,17,18)])
    odsfile.writerow(["Bool",True,False,True])
    odsfile.writerow(["Formula",1,2,3,ods.Formula("IF(A1=2,B1,C1)")])

Exemple #6
0
def odsWriteFormula(ods, formula):
    ods.writerow([odswriter.Formula(formula)])
    return 1