Python xls文件和xlsx文件格式互相转换
1. xls文件另存为xlsx
import win32com.client
xls_path = 'D:\\1_Work_Task\\01_Integrate_test\\2_IFC2.0_integrate_test\\test_report\\report.xls'
e = win32com.client.Dispatch('Excel.application')
pro = e.Workbooks.Open(xls_path)
file_Name = os.path.splitext(xls_path)
new_excel_path = file_Name[0] + "_new.xlsx"
pro.SaveAs(new_excel_path, FileFormat=51)
pro.Close()
e.Application.Quit()
2. xlsx文件另存为xls
import win32com.client
xls_path = 'D:\\1_Work_Task\\01_Integrate_test\\2_IFC2.0_integrate_test\\test_report\\report.xlsx'
e = win32com.client.Dispatch('Excel.application')
pro = e.Workbooks.Open(xls_path)
file_Name = os.path.splitext(xls_path)
new_excel_path = file_Name[0] + "_new.xls"
pro.SaveAs(new_excel_path, FileFormat=56)
pro.Close()
e.Application.Quit()