Python names the excel file with the date, that is, gets the date and writes it into the excel file name

import datetime

date_today = datetime.date.today()
date_today = date_today.strftime('%Y%m%d')
dotname = os.path.splitext('D:/test/test.xlsx')[1]#suffix format ,.xlsx
filename = os.path.basename('D:/test/test.xlsx')#The file name after stripping the path, test.xlsx
filename = filename.split(".")[0]# Stripping the path, The file name of the suffix, test
targetfile = D:/test/'+filename+'_'+date_today()+dotname

df = pd.DataFrame(pd.read_excel('D:/test/test.xlsx',‘Sheet1’))

#xxxx processing processing

df.to_excel(targetfile,sheet_name='Sheet1',index=False)

or

wb = load_workbook(targetfile)
ws = wb['Sheet1']

#xxxx processing processing

wb.save(targetfile)

Guess you like

Origin blog.csdn.net/qwcsl/article/details/129955011