I'm using python to process some data. In the beginning, I have an .ods file with many sheets. I need to edit cells inside each sheets and save it as a new file. I followed https://stackoverflow.com/a/5285650/2363712 to achieve generating new files while keeping the same format by preparing separate .xls reference files from the original .ods and then copy/edit these files with python.
class xls_form:
'''
modify the original file start from row 3
'''
def __init__(self, in_filename="ref_excel_form3.xls"):
self.inBook = xlrd.open_workbook(in_filename, formatting_info=True, on_demand=True)
# Copy the workbook, and get back the style
# information in the `xlwt` format
self.outBook, self.outStyle = copy2(self.inBook)
def write2(self, sheet_idx, x, y, val):
insheet = self.inBook.sheet_by_index(sheet_idx)
xf_index = insheet.cell_xf_index(3, y)
saved_style = self.outStyle[xf_index]
self.outBook.get_sheet(sheet_idx).write(x, y, val, saved_style)
def fill_dic_in(self, sheet_idx, dic_data, col_map):
col_i = 0
for k, v in dic_data.items():
for k1, v1 in v.items():
row_i = 3
for val in v1:
self.write2(sheet_idx, row_i, col_map[col_i], val)
row_i += 1
col_i += 1
def export(self, out_filename="write_excel_form3_out.xls"):
self.outBook.save(out_filename)
My question now is that I need to combine these modified .xls files back to one .ods file with several sheets (also keeping the same format). I know libreoffice can be used in cmd to transfer by Python convert Excel File (xls or xlsx) to/from ODS one by one. Is there a way to combine them into one file? Thank you for any suggestion but No pandas please :)