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+opencv图像风格迁移的实现方法讲解

Python如何输出星号组成的菱形图形?

Python能做嵌入式吗

Python去重函数是什么

Python文件操作a+与a模式的区别

Python迭代器定义与简单用法分析

Python中pillow知识点学习

Python之io多路复用之epoll

Python验证码识别教程之利用投影法、连通域法分割图片

Python安装jieba失败怎么办?

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




打赏

取消

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

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

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

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

评论

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