131. Working with Excel Files
import openpyxl
# Create a new workbook and select the active sheet
workbook = openpyxl.Workbook()
sheet = workbook.active
# Writing data to cells
sheet['A1'] = 'Name'
sheet['B1'] = 'Age'
sheet['A2'] = 'Alice'
sheet['B2'] = 30
sheet['A3'] = 'Bob'
sheet['B3'] = 25
# Save the workbook to a file
workbook.save('people.xlsx')
print("Excel file created and data written.")Last updated