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安装到哪个盘

Python 文件操作详解

简介Python中的__init__的作用

Python基本数据类型有哪些

Python后到底能干什么

Python中四种锁的使用示例(代码)

Python实现自动刷博客浏览量经验分享

isinstance在Python中的意思是什么?

Python如何使用文本框

Python库怎么安装

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




打赏

取消

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

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

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

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

评论

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