ITeye博客

Python Excel

2057 · 2013-09-10 17:21 · python · 编程语言 · Markdown

安装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")

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。