I have some *.xls (excel 2003) files, and I want to convert those files into xlsx (excel 2007).
I use the uno python package, when I save the documents, I can set the Filter name: MS Excel 97 But there is no Filter name like 'MS Excel 2007',
How can set the the filter name to convert xls to xlsx ?
Save to Different File Formats Click the File tab. Click Save As. Click the Save as type list arrow. The default file type is an XLSX Excel file, but you can choose from plenty of other file formats in this menu.
For compatibility, XLS has higher compatibility than XLSX. XLS is readable by all Microsoft Excel versions while XLSX is only readable by Excel 2007 and later versions. besides, XLS is able to hold the spreadsheets either including Macros or not, while XLSX isn't capable to support Macros.
You need to have win32com installed on your machine. Here is my code:
import win32com.client as win32 fname = "full+path+to+xls_file" excel = win32.gencache.EnsureDispatch('Excel.Application') wb = excel.Workbooks.Open(fname) wb.SaveAs(fname+"x", FileFormat = 51) #FileFormat = 51 is for .xlsx extension wb.Close() #FileFormat = 56 is for .xls extension excel.Application.Quit()
Here is my solution, without considering fonts, charts and images:
$ pip install pyexcel pyexcel-xls pyexcel-xlsx
Then do this::
import pyexcel as p p.save_book_as(file_name='your-file-in.xls', dest_file_name='your-new-file-out.xlsx')
If you do not need a program, you could install one additinal package pyexcel-cli::
$ pip install pyexcel-cli $ pyexcel transcode your-file-in.xls your-new-file-out.xlsx
The transcoding procedure above uses xlrd and openpyxl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With