Python Openpyxl 和下载问题?

Python Openpyxl and download issues?

正在尝试从 Excel 下载到 Python 但未显示列名称 来自 excel sheet。另外,我得到第二列全为零。下面是前两行,但它应该有列名(数据、收盘价、开盘价等)

**

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()

**

(没有列名称,但它在 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

尝试从 0 开始你的范围。

而不是这个

for r in range(1,rows+1):
    for c in range(1,cols+1):
        print(sheet.cell(row=r, column=c).value,end="    ")

试试这个

for r in range(0,rows):
        for c in range(0,cols):
            print(sheet.cell(row=r, column=c).value,end="    ")