How to append values to excel sheet using Openpyxl

Hello coders!!

Here, we will learn how to append values to an excel sheet using openpyxl.

To do this, we first need to import Workbook from openpyxl as follows:

import openpyxl 
from openpyxl import Workbook

Then, we need to create a workbook and select a spreadsheet to work on as directed:

wb=Workbook() 
w_sheet=wb.active

Now, we will make the data we would like to enter into the sheet.

Class_A = ( ("Name","Roll no."),
            ("riddhi",2), 
            ("ria", 51), 
            ("Maithili", 14), 
            ("rishu", 41), 
            ("Peter",45.63) )

Then, we will create a for loop to append the values as shown below:

for i in Class_A: 
    w_sheet.append(i)

Then, save the spreadsheet:

wb.save('ctpl.xlsx')

The following data will be added to your sheet.

 

Leave a Reply

Your email address will not be published. Required fields are marked *