Skip to main content

Create a Excel Workbook and add Data

· One min read
  1. Open Terminal and Install openpyxl

    python -m pip install openpyxl

  1. Open VSCode and Create a file excel_practice.py and write the below code
import openpyxl  

name_list = [
    "Ram",
    "Lakshman",   
    "Sita",
    "Hanuman"
]

roll_number_list = ["001", "002", "003", "004"]

# Workbook initialize
wb = openpyxl.Workbook()

# Take the active sheet and name title and column headers
sheet = wb.active
sheet.title = "Students"
sheet["A1"] = "Name"
sheet["B1"] = "Roll Number"

# Append the values to the sheet
for name, number in zip(name_list, roll_number_list):
    sheet.append([name, number])

# Save the Excel
wb.save("Students_Data.xlsx")

  1. No run the code

  2. You can see the Students_Data.xlsx created.