Python OPENPYXL Append Values














































Python OPENPYXL Append Values



Python OPENPYXL Append Values

Python provides the Openpyxl module, which is used to deal with Excel files without involving third-party Microsoft application software. By using this module, we can have control over excel without open the application. It is used to perform excel tasks such as read data from excel file, or write data to the excel file, draw some charts, accessing excel sheet, renaming sheet, modification (adding and deleting) in excel sheet, formatting, styling in the sheet, and any other task. Openpyxl is very efficient to perform these tasks for you. Data scientists often use the Openpyxl to perform different operations such as data copying to data mining as well as data analysis.

With the append method, we can append a group of values at the bottom of the current sheet. Openpyxl provides an append() method, which is used to append the group of values. We can append any type of value. These values are appended at the bottom of the current working sheet. Consider the following code:

from openpyxl import Workbook

wb = Workbook()

sheet = wb.active    

data = (  

    (114850),  

    (813082),  

    (205172),  

    (211460),  

    (284149),  

    (746553),  

    ("Peter"'Andrew',45.63)  

)  

  

for i in data:  

    sheet.append(i)  

wb.save('appending_values.xlsx')  

 

In the example, we append three columns of data into the current sheet.

data = (  

    (114850),  

    (813082),  

    (205172),  

    (211460),  

    (284149),  

    (746553),  

    ("Peter"'Andrew',45.63)  

)  

 

The data is stored in a tuple of tuples.

for i in data:  

    sheet.append(i)  

 

We go through the container row by row and insert the data row with the append method.

Output:

 Openpyxl Append values


Comments