python将xls转换为xlsx
作者:互联网
注意
win32 excel需要绝对路径,不支持相对路径
转换方法,获取当前路径 os.getcwd()
,用os.path.join
+ 文件名组合成绝对路径
workbook.save(f'RPA Amazon WK{wk_num} {saturday_meihong}.xls')
path = os.path.join(os.getcwd(),f'RPA Amazon WK{wk_num} {saturday_meihong}.xls')
print(path)
xls_to_xlsx(path)
def xls_to_xlsx(file):
import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(file)
wb.SaveAs(file + "x", FileFormat=51) # FileFormat = 51 is for .xlsx extension
wb.Close() # FileFormat = 56 is for .xls extension
excel.Application.Quit()
参考
https://blog.csdn.net/yizhuanlu9607/article/details/89227908
标签:xlsx,python,os,excel,file,path,xls 来源: https://blog.csdn.net/nongcunqq/article/details/122838334