Tried @Jhon's solution 1st, then I turned into pyexcel as a solution
pyexcel.save_as(file_name=oldfilename, dest_file_name=newfilename)
It works properly until I tried to package my project to a single exe file by PyInstaller, I tried all hidden imports option, following error still there:
File "utils.py", line 27, in __enter__
pyexcel.save_as(file_name=self.filename, dest_file_name=newfilename)
File "site-packages\pyexcel\core.py", line 77, in save_as
File "site-packages\pyexcel\internal\core.py", line 22, in get_sheet_stream
File "site-packages\pyexcel\plugins\sources\file_input.py", line 39, in get_da
ta
File "site-packages\pyexcel\plugins\parsers\excel.py", line 19, in parse_file
File "site-packages\pyexcel\plugins\parsers\excel.py", line 40, in _parse_any
File "site-packages\pyexcel_io\io.py", line 73, in get_data
File "site-packages\pyexcel_io\io.py", line 91, in _get_data
File "site-packages\pyexcel_io\io.py", line 188, in load_data
File "site-packages\pyexcel_io\plugins.py", line 90, in get_a_plugin
File "site-packages\lml\plugin.py", line 290, in load_me_now
File "site-packages\pyexcel_io\plugins.py", line 107, in raise_exception
pyexcel_io.exceptions.SupportingPluginAvailableButNotInstalled: Please install p
yexcel-xls
[3192] Failed to execute script
Then, I jumped to pandas:
pd.read_excel(oldfilename).to_excel(newfilename, sheet_name=self.sheetname,index=False)
Update @ 21-Feb 2020
openpyxl provides the function: append
enable the ability to insert rows to a xlxs file which means user could read the data from a xls file and insert them into a xlsx file.
- append([‘This is A1’, ‘This is B1’, ‘This is C1’])
- or append({‘A’ : ‘This is A1’, ‘C’ : ‘This is C1’})
- or append({1 : ‘This is A1’, 3 : ‘This is C1’})
Appends a group of values at the bottom of the current sheet:
- If it’s a list: all values are added in order, starting from the first column
- If it’s a dict: values are assigned to the columns indicated by the keys (numbers or letters)