2016年3月29日 星期二

[python] python 3.x read excel xls file in list.

office doc
https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html?p=4966

import xlrd
def open_file(path):
    """
    Open and read an Excel file
    """
    book = xlrd.open_workbook(path)
    # print number of sheets
    print book.nsheets
    # print sheet names
    print book.sheet_names()
    # get the first worksheet
    first_sheet = book.sheet_by_index(0)
    # read a row
    print first_sheet.row_values(0)
 
    # get how many rows in this sheet
    print first_sheet.nrows
 
    # read a cell
    cell = first_sheet.cell(0,0)
    print cell
    print cell.value
    # read a row slice
    print first_sheet.row_slice(rowx=0,
                                start_colx=0,
                                end_colx=2)
   return
 
 
 
 

沒有留言:

張貼留言