[python]Read excel by xlrd

2021-8-26 写技术

import xlrd

def read_excel(fromFile, fromSheet):
    workbook = xlrd.open_workbook(fromFile)
    print(workbook.sheet_names())

    sheet = workbook.sheet_names()[fromSheet]
    sheet = workbook.sheet_by_index(fromSheet)

    print(sheet)
    row = sheet.nrows
    col = sheet.ncols
    print(row, col)

    for i in range(0, row):
        for j in range(0, col):
            v = sheet.cell(i, j).value
            print(v," ", end="")
        print(" ")


read_excel("nicholas.xls", 0)

标签: python

发表评论:

Powered by anycle 湘ICP备15001973号-1