Kirish I. Umumiy qism


Download 1.09 Mb.
bet12/12
Sana28.12.2022
Hajmi1.09 Mb.
#1024933
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
Kurs ishi

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).

    1. automate_excel('sales_january.xlsx')

    2. automate_excel('sales_february.xlsx')

    3. automate_excel('sales_march.xlsx')

    Yoki avval ushbu uchta hisobotni birlashtiribpd.concat(), keyin funktsiyani faqat bir marta qo'llashingiz mumkin.

    1. # read excel files

    2. excel_file_1 = pd.read_excel('sales_january.xlsx')

    3. excel_file_2 = pd.read_excel('sales_february.xlsx')

    4. excel_file_3 = pd.read_excel('sales_march.xlsx')

    5. # concatenate files

    6. new_file = pd.concat([excel_file_1,

    7. excel_file_2,

    8. excel_file_3], ignore_index=True)

    9. # export file

    10. new_file.to_excel('sales_2021.xlsx')

    11. # apply function

    12. automate_excel('sales_2021.xlsx')

    Download 1.09 Mb.

    Do'stlaringiz bilan baham:
  • 1   ...   4   5   6   7   8   9   10   11   12




    Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
    ma'muriyatiga murojaat qiling