I'm trying to add row data using pyexcel. In the cookbook I have found a method called update_rows() it takes three arguments (fileToRead, list/dictionary, outputFile)
I get the following error: NotImplementedError: We do not overwrite files
I can see that this is not the method I'm looking for. I'm open to any module making use of .ods format if it better suits my needs.
import os
import pyexcel
import pyexcel.ext.ods
from pyexcel.cookbook import update_rows
import datetime
def mkExcel(dataList, tDate, pathToFile):
whereToGo = os.path.join(os.path.expanduser(pathToFile), "Archive_%s.ods") % tDate
if not os.path.exists(whereToGo):
dataList = pyexcel.utils.dict_to_array(dataList)
# "output.xls" "output.xlsx" "output.ods" "output.xlsm"
dataList = pyexcel.Sheet(dataList)
print
dataList
dataList.save_as(whereToGo)
else:
dSheet = pyexcel.load(whereToGo, name_columns_by_row=0)
dataList = pyexcel.utils.dict_to_array(dataList)
custom_row = {"Row -1": [11, 12, 13]}
## update_rows(existing.ods, custom_row, new.ods)
update_rows(dSheet, custom_row, whereToGo)
now = datetime.datetime.now()
now = '%s-%s-%s' % (now.year, now.month, now.day)
example_dict = {"Column 1": [1, 2, 3], "Column 2": [4, 5, 6], "Column 3": [7, 8, 9]}
here = os.getcwd()
mkExcel(example_dict, now, here)