Python Excel

安装lib
easy_install xlrd


def handle(path):
    book = open_workbook(path)
    sheet = book.sheet_by_index(0)

    print sheet.name
    print sheet.nrows
    print sheet.ncols

    for row_index in range(sheet.nrows):
        for col_index in range(sheet.ncols):
            prinf sheet.cell(row_index,col_index).value


有关excel时间的转换
可参考:
http://blog.donews.com/limodou/archive/2005/07/08/459100.aspx
__s_date = datetime.date(1899, 12, 31).toordinal() - 1
def getdate(date):
    if isinstance(date, float):
        date = int(date)
    d = datetime.date.fromordinal(__s_date + date)
    return d.strftime("%Y-%m-%d")




你可能感兴趣的:(python,Excel)