python如何读取excel表数据


当前第2页 返回上一页

99ff66bc4315a7e099339409ffa5d80.png

6、完整的程序代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

import xlrd

from xlrd import xldate_as_tuple

import datetime

#导入需要读取的第一个Excel表格的路径

data1 = xlrd.open_workbook(r'C:\Users\NHT\Desktop\Data\\test.xlsx')

table = data1.sheets()[0]

#创建一个空列表,存储Excel的数据

tables = []

#将excel表格内容导入到tables列表中

def import_excel(excel):

  for rown in range(excel.nrows):

   array = {'road_name':'','bus_plate':'','timeline':'','road_type':'','site':''}

   array['road_name'] = table.cell_value(rown,0)

   array['bus_plate'] = table.cell_value(rown,1)

   if table.cell(rown,2).ctype == 3:

     date = xldate_as_tuple(table.cell(rown,2).value,0)

     array['timeline'] = datetime.datetime(*date)

   array['road_type'] = table.cell_value(rown,3)

   array['site'] = table.cell_value(rown,4)

   tables.append(array)

if __name__ == '__main__':

  #将excel表格的内容导入到列表中

  import_excel(table)

  for i in tables:

    print(i)

更多相关免费学习推荐:python视频教程

以上就是python如何读取excel表数据的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python如何编出爱心

Python堆排序算法实例代码

Python怎么做网站

介绍Python的函数装饰器

perl和Python之间有什么区别?perl与Python的简单比较

Python学什么数据库

分享Python snownlp的实例教程

分享Python如何实现头像拼接技术/

Python能代替shell吗

解析Python中executemany和序列用法教程

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...