如何导入" .xls"在python中

时间:2016-03-14 08:19:34

标签: python-2.7

我需要导入" .xls"在python中。 能否请你给我一个想法。我必须只导入一个excel文件而不是" .csv" file.Because csv file忽略了数字中的前导零。

1 个答案:

答案 0 :(得分:-1)

以下是代码示例:

import xlrd



def open_file(path):


    #Open and read an Excel file

    book = xlrd.open_workbook(path)

    print book.nsheets  # print number of sheets

    print book.sheet_names()  # print sheet names

    first_sheet = book.sheet_by_index(0)   # get the first worksheet

    print first_sheet.row_values(0) # read a row

    cell = first_sheet.cell(0,0)    # read a cell

    print cell

    print cell.value

    # read a row slice

    print first_sheet.row_slice(rowx=0,

                                start_colx=0,

                                end_colx=2)
if __name__ == "__main__":

    path = "test.xls"

    open_file(path)