码迷,mamicode.com
首页 > 其他好文 > 详细

从 EXCEL 导入数据

时间:2017-02-26 17:40:36      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:book   rom   datetime   work   导入数据   team   filename   mod   from   

 1 import xlrd
 2 from xlrd.xldate import XLDateAmbiguous
 3 
 4 file = ch02-xlsxdata.xlsx
 5 
 6 wb = xlrd.open_workbook(filename=file)
 7 
 8 ws = wb.sheet_by_name(Sheet1)
 9 
10 dataset = []
11 
12 for r in range(ws.nrows):
13     col = []
14     for c in range(ws.ncols):
15         col.append(ws.cell(r, c).value)
16         if ws.cell_type(r, c) == xlrd.XL_CELL_DATE:
17             try:
18                 print ws.cell_type(r, c)
19                 from datetime import datetime
20                 date_value = xlrd.xldate_as_tuple(ws.cell(r, c).value, wb.datemode)
21                 print datetime(*date_value)
22             except XLDateAmbiguous as e:
23                 print e
24     dataset.append(col)
25 
26 from pprint import pprint
27 
28 pprint(dataset)

 

从 EXCEL 导入数据

标签:book   rom   datetime   work   导入数据   team   filename   mod   from   

原文地址:http://www.cnblogs.com/boooobao/p/6444920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!