python处理excel之读:xlrd模块
# -*- coding:utf-8 -*-
import xlrd path = r'D:/工作簿1(已自动还原).xlsx' # 打开excel文件读取数据
data = xlrd.open_workbook(path)
# 获取excel中所有工作表sheets
sheets = data.sheets()
# 获取所有sheet的名称集合
sheet_names = data.sheet_names() # 获取sheet对象的三种方式
# 1
for i in range(len(sheets)):
sheet = sheets[i]
print(sheet)
# 2
for i in range(len(sheets)):
sheet = data.sheet_by_index(i)
print(sheet)
# 3
for i in range(len(sheet_names)):
sheet = data.sheet_by_name(sheet_names[i])
print(sheet) # 行的操作
for i in range(len(sheets)):
sheet = sheets[i]
rows = sheet.nrows
cols = sheet.ncols
for j in range(rows):
print(sheet.row_values(j))
for k in range(cols):
value = sheet.row_values(j)[k]
if value: # 去除空值
print(value) # 列的操作
for i in range(len(sheets)):
sheet = sheets[i]
rows = sheet.nrows
cols = sheet.ncols
for j in range(cols):
print(sheet.col_values(j))
print(sheet.col_types(j))
for k in range(rows):
value = sheet.col_values(j)[k]
if value:
print(value) # 单元格的操作
for i in range(len(sheets)):
sheet = sheets[i]
rows = sheet.nrows
cols = sheet.ncols
for j in range(rows):
for k in range(cols):
value = sheet.cell_value(j, k)
if value:
print(value)
python处理excel之读:xlrd模块的更多相关文章
- python读写Excel文件--使用xlrd模块读取,xlwt模块写入
一.安装xlrd模块和xlwt模块 1. 下载xlrd模块和xlwt模块 到python官网http://pypi.python.org/pypi/xlrd下载模块.下载的文件例如:xlrd-0.9. ...
- python操作Excel读写--使用xlrd和xlwt
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 进入到解压文件路径,输入 setup.py ...
- python操作Excel读写--使用xlrd
一.安装xlrd模块 到python官网下载http://pypi.python.org/pypi/xlrd模块安装,前提是已经安装了python 环境. 二.使用介绍 1.导入模块 import x ...
- 【Python】excel读写操作 xlrd & xlwt
xlrd ■ xlrd xlrd模块用于读取excel文件内容 基本用法: workbook = xlrd.open_workbook('文件路径') workbook.sheet_names() # ...
- python操作Excel读写--使用xlrd (转)
(转自:http://www.cnblogs.com/lhj588/archive/2012/01/06/2314181.html) 一.安装xlrd模块 到python官网下载http://pypi ...
- Python之excel第三方库xlrd和xlwt
Python读取excel表格的库xlrd,首先安装xlrd: pip3 install xlrd 代码: #!usr/bin/env python3 #!-*-coding=utf-8 -*- '' ...
- python 读取 execl 文件 之 xlrd 模块
1. 安装 xlrd模块 pip install xlrd 2. 读取文件内容 #!/usr/bin/env python3 import xlrd name = r"E:\excel\yo ...
- python学习,excel操作之xlrd模块常用操作
import xlrd ##工作表## #打开excel f = xlrd.open_workbook("test.xlsx") file = f.sheet_by_name(&q ...
- python操作excel的读、计算、写----xlrd、copy
import xlrd from xlutils.copy import copy class ExcelUtil: def __init__(self,excel_path=None,index=N ...
随机推荐
- 探索未知种族之osg类生物---呼吸分解之advance
回顾 我们用了两节的内容才堪堪讲解完ViewerBase::frame()函数中调用的realize()---Viewer:: realize()函数.我们简单的总结就是Viewer:: realiz ...
- pop回到之前的某一个页面
循环遍历 - (void)backHome:(UIButton *)button { self.navigationController.navigationBarHidden = NO; 4 Cas ...
- Eclipse快速生成覆盖方法、Getter、Setter的方法
点击鼠标右键 --> Source --> 直接使用快捷键 Alt+Shift+s
- [Jmeter] Concurrency Thread Group
Concurrency Thread Group : https://jmeter-plugins.org/wiki/ConcurrencyThreadGroup/ 参数介绍: Target Conc ...
- Python学习1 基础数据类型
一.字符串 1.去除首尾字符 str_test = 'Hello World!' str_test.split()#将字符串分割为列表str_test. ...
- ssh密钥讲解
我们用ssh连接机器时候需要输用户名.密码,但是直接写账户文件的时候由于用的是明文,就存在安全的问题了.别人一旦截取了数据就获得了隐私了.这时候就用上ssh的密钥. ssh的密钥存是成对出现的,一个叫 ...
- JDK8集合类源码解析 - HashSet
HashSet 特点:不允许放入重复元素 查看源码,发现HashSet是基于HashMap来实现的,对HashMap做了一次“封装”. private transient HashMap<E,O ...
- 移动开发学习touchmove
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- python包与模块导入
一 .module 通常模块为一个文件,直接使用import来导入就好了.可以作为module的文件类型有".py".".pyo".".pyc&quo ...
- dedecms首页搜索 添加仿百度下拉框
1:找到uploads/templets/default/head.htm 2: 找到 <input name="q" type="text" clas ...