Easy Steps to Create Excel Workbooks in Python

Easy Steps to Create Excel Workbooks in Python

·

1 min read

Sure, you can use the openpyxl library in Python to create an Excel workbook. Here's a basic example:

from openpyxl import Workbook

# Create a workbook and select the active worksheet
wb = Workbook()
ws = wb.active

# Add some data
ws['A1'] = 'Hello'
ws['B1'] = 'World'

# Save the workbook as an Excel file
wb.save('example.xlsx')

This will create an Excel file named example.xlsx with the text "Hello" in cell A1 and "World" in cell B1. Please ensure you have the openpyxl library installed. If not, you can install it using pip: pip install openpyxl.