-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompleteXcel.py
27 lines (21 loc) · 948 Bytes
/
completeXcel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import openpyxl
def write_to_excel(enterprise_name, contact_person, date, mail, excel_file="book.xlsx"):
try:
# Load the Excel workbook
wb = openpyxl.load_workbook(excel_file)
# Select the first sheet (you can modify this if your file has multiple sheets)
sheet = wb.active
# Find the next available row
next_row = sheet.max_row + 1
# Write the data to the corresponding cells
sheet.cell(row=next_row, column=1, value=enterprise_name)
sheet.cell(row=next_row, column=2, value=contact_person)
sheet.cell(row=next_row, column=3, value=date)
sheet.cell(row=next_row, column=4, value=mail)
# Save the changes to the Excel file
wb.save(excel_file)
print(f"COMPLETEXCEL: Data written to {excel_file} successfully!")
return 0
except Exception as e:
print(f"COMPLETEXCEL: An error occurred: {e}")
return 1