Reputation: 33
Trying to download from Excel into Python but Name of the columns do not appear from the excel sheet. Also, I get a second columns with all zeros. Below are the first two lines but it should have the columns names (data, close price, open price, etc)
**
import openpyxl
path="C:\Data\EXCELAMZNPY.xlsx"
workbook = openpyxl.load_workbook(path)
sheet=workbook.active #workbook.get_sheet_by_name("sheet1")
rows = sheet.max_row#1260
cols = sheet.max_column#7
print(rows)
print(cols)
for r in range(1,rows+1):
for c in range(1,cols+1):
print(sheet.cell(row=r, column=c).value,end=" ")
print()
**
(NO COLUMN NAME BUT IT IS ON THE EXCEL SHEET!)
2016-02-18 00:00:00 541.19 541.2 523.73 525 4735008 AMZN
2016-02-19 00:00:00 520.71 535.95 515.35 534.9 4974717 AMZN
Upvotes: 0
Views: 31
Reputation: 3365
try starting your ranges from 0.
Instead of this
for r in range(1,rows+1):
for c in range(1,cols+1):
print(sheet.cell(row=r, column=c).value,end=" ")
try this
for r in range(0,rows):
for c in range(0,cols):
print(sheet.cell(row=r, column=c).value,end=" ")
Upvotes: 1