---
title: "Python Excel"
author: "2057"
date: "2013-09-10T17:21:53Z"
tags: []
categories: ["编程语言"]
slug: "python-excel"
draft: false
lastmod: "2013-09-10T17:21:53Z"
id: 1940265
url: "https://2057.iteye.com/blog/1940265"
---

**安装lib**

```python
easy_install xlrd
```
 


```python

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>

```python

__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")

```