Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
1.4 kB
3
Indexable
Never
import pandas as pd
import shutil
from openpyxl import load_workbook

maszynowka = ['FEELER', 'INT200SY', 'INT300SY', 'MAT2']
montaz = ['AS_BOND', 'AS_BPanl']

df_report = pd.read_excel('Report Report Bookings by Machine no data.xlsx', header=1)
df_report = df_report.loc[df_report['Work centre'].isin(maszynowka)]
df_report.to_excel('wynik2.xlsx', index=False)

old_file = '26-06-2024 Operators Booking (Machining) no data.xlsx'
new_file = 'NEW FILE Operators Booking (Machining).xlsx'
shutil.copy(old_file, new_file)

wb = load_workbook(new_file)
ws = wb['Report Bookings']
df_wynik2 = pd.read_excel('wynik2.xlsx', header=0)

for row in range(3, ws.max_row +1):
    for col in range(1, 16):
        ws.cell(row=row, column=col).value = None

for i in range(len(df_wynik2)):
    for j in range(len(df_wynik2.columns)):
        ws.cell(row=i+3, column=j+1, value=df_wynik2.iat[i, j])

wb.save(new_file)
wb.close()
print('Zrobione')

#for row in range(3, ws.max_row + 1):
    #formula = f"=SUMA.WARUNKÓW(Master!S:S, Master!A:A, 'Report Bookings'!C{row}, Master!M:M, 'Report Bookings'!E{row}, Master!N:N, 'Report Bookings'!G{row})"
    #ws[f'P{row}'].value = formula.format(row)

#with pd.ExcelWriter(new_file, engine='openpyxl', mode='a', if_sheet_exists='replace') as writer:
    #df_report.to_excel(writer, sheet_name='Report Bookings', index=False)
Leave a Comment