python如何批量处理excel数据?

coldplay.xixi
Freigeben: 2020-06-15 11:09:42
Original
5533 人浏览过

python如何批量处理excel数据?

python如何批量处理excel数据?

python批量处理excel数据的方法:

excel的内容需要有规律,python才能按顺序读取出来。 比如按行按列读取。

一、安装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

简单的写入

row = 0

col = 0

# 类型 0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error

ctype = 1 value = '单元格的值'

xf = 0 # 扩展的格式化

table.put_cell(row, col, ctype, value, xf)

table.cell(0,0) #单元格的值'

table.cell(0,0).value #单元格的值'

推荐教程:《python视频教程

以上是python如何批量处理excel数据?的详细内容。更多信息请关注PHP中文网其他相关文章!

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Neueste Artikel des Autors
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!