top of page
back.jpg

Read data From Excel Python

crystgandhi

import openpyxl

# Load the Excel workbook
workbook = openpyxl.load_workbook("C://Users/Nikil/PycharmProjects/pythonBasics/Userdata.xlsx")

# Access the specified sheet by name (using workbook[sheet_name])
sheet = workbook["Sheet1"]

# Get the number of rows and columns in the sheet
rows = sheet.max_row
columns = sheet.max_column
print("Number of rows:", rows)
print("Number of columns:", columns)

# Iterate through each row and column to print cell values
for r in range(2, rows + 1):  
# Start from the second row (assuming headers in the first row)
    for c in range(1, columns + 1):
        # Print the value of each cell, separated by spaces
        print(sheet.cell(row=r, column=c).value, end="      ")
# Move to the next line after printing values of all columns in the current row
    print()

2 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a...

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl +...

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page