python如何导入excel


当前第2页 返回上一页

例:

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

26

27

28

29

# -*- coding: utf-8 -*-

import xlrd

from datetime import date,datetime

def read_excel():

#文件位置

ExcelFile=xlrd.open_workbook(r'C:\Users\Administrator\Desktop\TestData.xlsx')

#获取目标EXCEL文件sheet名

print ExcelFile.sheet_names()

#------------------------------------

#若有多个sheet,则需要指定读取目标sheet例如读取sheet2

#sheet2_name=ExcelFile.sheet_names()[1]

#------------------------------------

#获取sheet内容【1.根据sheet索引2.根据sheet名称】

#sheet=ExcelFile.sheet_by_index(1)

sheet=ExcelFile.sheet_by_name('TestCase002')

#打印sheet的名称,行数,列数

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

#获取整行或者整列的值

rows=sheet.row_values(2)#第三行内容

cols=sheet.col_values(1)#第二列内容

print cols,rows

#获取单元格内容

print sheet.cell(1,0).value.encode('utf-8')

print sheet.cell_value(1,0).encode('utf-8')

print sheet.row(1)[0].value.encode('utf-8')

#打印单元格内容格式

print sheet.cell(1,0).ctype

if__name__ =='__main__':

read_excel()

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

返回前面的内容

相关阅读 >>

Python中的排序操作和heapq模块的介绍(代码示例)

Python中spyder怎么安装

Python 实现在文件中的每一行添加一个逗号

介绍Python爬取网页

Python连接sqlite的实例教程

比较讲解Python中的*args和 **kwargs用法

Python的解释器是什么?

Python为什么编码声明

pytho中字典操作方法介绍(代码示例)

Python是前端还是后端

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




打赏

取消

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

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

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

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

评论

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