python操作Excel读写--使用xlrd
来源:互联网 发布:linux 创建home目录 编辑:程序博客网 时间:2024/06/15 17:47
一、安装xlrd模块
到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境。
二、使用介绍
1、导入模块
import xlrd
2、打开Excel文件读取数据
data = xlrd.open_workbook('excelFile.xls')
3、使用技巧
获取一个工作表
table = data.sheets()[0] #通过索引顺序获取
table = data.sheet_by_index(0) #通过索引顺序获取
table = data.sheet_by_name(u'Sheet1')#通过名称获取
获取整行和整列的值(数组)
table.row_values(i)
table.col_values(i)
获取行数和列数
nrows = table.nrows
ncols = table.ncols
循环行列表数据
for i in range(nrows ):
print table.row_values(i)
单元格
cell_A1 = table.cell(0,0).value
cell_C4 = table.cell(2,3).value
使用行列索引
cell_A1 = table.row(0)[0].value
cell_A2 = table.col(1)[0].value
三、Demo代码
Demo代码其实很简单,就是读取Excel数据。
import xlwtfrom datetime import datetime style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',num_format_str='#,##0.00')style1 = xlwt.easyxf(num_format_str='D-MMM-YY') wb = xlwt.Workbook()ws = wb.add_sheet('A Test Sheet') ws.write(0, 0, 1234.56, style0)ws.write(1, 0, datetime.now(), style1)ws.write(2, 0, 1)ws.write(2, 1, 1)ws.write(2, 2, xlwt.Formula("A3+B3")) wb.save('example.xls')
然后是可以正常执行,生成对应的excel文件的,效果为:
阅读全文
1 0
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写(使用xlrd)
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- python操作Excel读写--使用xlrd
- mac iterm2 配置 sz rz 命令上传下载文件
- 数据结构和算法
- XListView汇总
- Java数据结构详解(一)-Collection接口
- 调用追踪存储展示应用——zipkin环境搭建
- python操作Excel读写--使用xlrd
- idea使用generator自动生成Mybatis代码以及idea插件的使用
- 数据库异常com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException
- 指令与寄存器
- jenkings
- leetcode 210. Course Schedule II 拓扑排序 + HashSet
- Spring MVC 与Struts2的区别
- Java Language and Virtual Machine Specifications
- js基础-富文本编辑器