Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

How to print out Excel file data in column structure in Python

I'm very new to Python but I've learned enough to print out the data in a specified range on Sheet 1 in a specified Excel workbook. The current code below will do that but in the Terminal window, each 5 column row is printed vertically in one long column so to speak. How would I modify the code to get it to print out with each 5 column row spread out horizontally as it is in Excel? I'm interested in doing that because 1) it would be easier to read, and 2) just to see if Python will do that.

path = r'C:\Users\t0122059\Documents\ACDetails.xlsx'

f = open(path, 'rb')
print(f.read())

# https://openpyxl.readthedocs.io/en/stable/usage.html

from openpyxl import load_workbook
wb = load_workbook(path)

for row in range(1, 12):
    for col in range(1, 6):
        print(wb.worksheets[0].cell(row, col).value)
print('inspect')

Open in new window

Thanks,
John
Avatar of John Carney
John Carney
Flag of United States of America image

ASKER

path = r'C:\Users\t0122059\Documents\ACDetails.xlsx'

f = open(path, 'rb')
print(f.read())

# https://openpyxl.readthedocs.io/en/stable/usage.html

from openpyxl import load_workbook
wb = load_workbook(path)

for row in range(1, 12):
    for col in range(1, 6):
        print(wb.worksheets[0].cell(row, col).value)
print('inspect')

Open in new window

SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, gentlemen!