Kirish I. Umumiy qism
Download 1.09 Mb.
|
Kurs ishi
- Bu sahifa navigatsiya:
- Funktsiyani bir nechta Excel fayllariga qollash
for i in excel_alphabet:
if i!='A': sheet[f'{i}{max_row+1}'] = f'=SUM({i}{min_row+1}:{i}{max_row})' sheet[f'{i}{max_row+1}'].style = 'Currency' sheet[f'{excel_alphabet[0]}{max_row+1}'] = 'Total' # getting month name month_name = month_and_extension.split('.')[0] # formatting the report sheet['A1'] = 'Sales Report' sheet['A2'] = month_name.title() sheet['A1'].font = Font('Arial', bold=True, size=20) sheet['A2'].font = Font('Arial', bold=True, size=10) wb.save(f'report_{month_and_extension}') return Funktsiyani bitta Excel fayliga qo'llash Tasavvur qilaylik, biz yuklab olgan asl fayl sales_2021 deb nomlangan.supermarket_sales o'rniga xlsx.xlsx. Hisobotga formulani qo'llash uchun biz quyidagilarni yozamiz: automate_excel('sales_2021.xlsx') Ushbu kodni ishga tushirgandan so'ng siz Report_2021 deb nomlangan Excel faylini olasiz.xlsx Python skriptingiz joylashgan papkada. Funktsiyani bir nechta Excel fayllariga qo'llash Tasavvur qilaylik, endi bizda faqat oylik Excel sales_january fayllari mavjud.xlsx, sales_february.xlsx va sales_march.xlsx (ushbu fayllarni GitHub-da topish mumkin). automate_excel('sales_january.xlsx') automate_excel('sales_february.xlsx') automate_excel('sales_march.xlsx') Yoki avval ushbu uchta hisobotni birlashtiribpd.concat(), keyin funktsiyani faqat bir marta qo'llashingiz mumkin. # read excel files excel_file_1 = pd.read_excel('sales_january.xlsx') excel_file_2 = pd.read_excel('sales_february.xlsx') excel_file_3 = pd.read_excel('sales_march.xlsx') # concatenate files new_file = pd.concat([excel_file_1, excel_file_2, excel_file_3], ignore_index=True) # export file new_file.to_excel('sales_2021.xlsx') # apply function automate_excel('sales_2021.xlsx') Download 1.09 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling