Openpyxl Append values




  • 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
 Openpyxl Append

Openpyxl Append

Sample Code

from openpyxl import Workbook  
wb = Workbook()  
sheet = wb.active
data = (  
    (11, 48, 50),  
    (81, 30, 82),  
    (20, 51, 72),  
    (21, 14, 60),  
    (28, 41, 49),  
    (74, 65, 53),  
    ("Kaashiv", 'infotech',45.63)  
)  
fori in data:  
sheet.append(i)  
wb.save('appending_values.xlsx')

Output

Openpyxl append output

Read Also

Openpyxl Iterate by Rows

  • The openpyxl provides the iter_row() function, which is used to read data corresponding to rows.
 Openpyxl Iterate Row

Openpyxl Iterate Row

Sample Code

from openpyxl import Workbook  
wb = Workbook()  
sheet = wb.active
rows = (  
    (11, 22, 33, 44),  
    (10, 20, 30, 40),  
    (5, 10, 15, 20),  
    (65, 12, 89, 53),  
    (12, 24, 36, 48),  
    (34, 51, 76, 42)  
)  
for row in rows:  
sheet.append(row)  
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=6, max_col=4):  
for cell in row:  
print(cell.value, end=" ")  
print()

wb.save('iter_rows.xlsx')  

Openpyxl Iterate by Column

  • The openpyxl provides iter_col() method which return cells from the worksheet as columns.
from openpyxl import Workbook  
wb = Workbook()  
sheet = wb.active
rows = (  
    (11, 22, 33, 44),  
    (10, 20, 30, 40),  
    (5, 10, 15, 20),  
    (65, 12, 89, 53),  
    (12, 24, 36, 48),  
    (34, 51, 76, 42)  
)  
for row in rows:  
sheet.append(row)  
for row in sheet.iter_cols(min_row=1, min_col=1, max_row=6, max_col=3):  
for cell in row:  
print(cell.value, end=" ")  
print()
wb.save('iterbycols.xlsx')  

Output

Openpyxl iterate column output


Related Searches to Openpyxl Append values

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×