python-excel操作之xlrd
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++操作excel文件++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw_File = "C:\\Users\\zwx318792\\Desktop\\xls_test\\huawei.xls"
#获得一个操作工作簿的对象
rb_hw = open_excel(hw_File)
<xlrd.book.Book object at 0x036CC7F0> #获得工作簿所有的sheet个数
rb_hw.nsheets
20 #获得所有工作簿名字
rb_hw.sheet_names()
['Basic Info', '51.010-2', '51.010-4', '34.123-2', '34.121-2', '36.521-2', '36.523-2', '31.121', '31.124', '34.171', '37.571-3', '34.229', 'MMS', 'SUPL', 'FUMO', 'DM', 'NFC', 'VT', 'AT', 'ChangeRecord']
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++操作sheet表格++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#获得一个sheet对象,它是用来操作sheet的
sheet = rb_hw.sheets()[1]
sheet = rb_hw.sheet_by_index(1)
<xlrd.sheet.Sheet object at 0x039158B0> #sheet名称
sheet.name
'51.010-2' #sheet行
sheet.nrows
1109 #sheet列
sheet.ncols
13
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++操作行跟列++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#行内容
sheet.row(109)
[text:'A.1/105', number:105.0, text:'EGPRS Multislot Class10', text:'3GPP\xa0TS\xa005.02| B.1\n3GPP TS 45.002| B.1', text:'R99', text:'O', text:'yes | no', text:'No', text:'TSPC_Type_EGPRS_Multislot_Class10', empty:'', text:'是', text:'EGPRS', text:'协议']
#得到的是cell对象组成的列表 #列内容
sheet.col(2)
[xt:'A.25.1/17', text:'A.25.1/18', text:'A.25.1/19', text:'A.25.1/20', text:'A.25.1/21', text:'A.25.1/22', text:'A.25.1/23', text:'A.25.1/24', text:'A.25.1/25', text:'A.25.1/26', text:'A.25.1/27', text:'A.25.1/28', text:'A.25.1/29', text:'A.25.1/30', text:'A.25.1/31', text:'A.25.1/32', text:'A.25.1/33', text:'A.25.1/34', text:'A.25.1/35', text:'A.25.1/36', text:'A.25.1/37', text:'A.25.1/38', text:'A.25.1/39', text:'A.25.1/40', text:'A.25.1/41', text:'A.25.1/42', text:'A.25.1/43', text:'A.25.1/44', text:'A.25.1/45', text:'A.25.1/46', empty:'', empty:'', empty:'', empty:'', empty:'', text:'A.27/1', text:'A.27/2', text:'A.27/3', text:'A.27/4', text:'R', text:'R1', text:'R2', text:'R3', text:'R4', text:'R5', text:'R6', text:'R7', text:'R8', text:'R9', text:'R10', text:'R11', text:'R12']
#得到的是cell对象组成的列表 #获得某行(列)某几个单元格的内容
row = sheet.row_slice(0,1,6)
print(row)
[text:'3GPP TS 51.010-2', empty:'', empty:'', empty:'', text:'V12.5.0']
col = sheet.col_slice(3,5,7)
print(col)
[text:'3GPP TS 05.05| 2\n3GPP TS 45.005| 2\n\n', text:'3GPP TS 05.05| 2\n3GPP TS 45.005| 2\n\n']
#得到的是cell对象组成的列表 #我们还可以单独获得行(列表)的某个单元格的值或者type
row = sheet.row_values(0,1,6)
print(row)
['3GPP TS 51.010-2', '', '', '', 'V12.5.0']
row = sheet.row_types(2,3,4)
print(row)
array('B', [0])
col = sheet.col_values(2,3,5)
print(col)
['Type of Mobile Station', 'Feature "A" is used for "applicability" that is referenced in 51.010-2 for many test cases.\r\nYou will find the description in Annex B of this specification.']
col = sheet.col_types(2,3,5)
print(col) [1, 1]
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++操作单元格++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#获得一个cell对象,这个对象时用来操作单元格的
cell = sheet.cell(109,7)
print(cell)
text:'No' #获得单元格的类型
print(cell.ctype)
sheet.cell_type(109,7)
1 #获得单元格的内容
print(cell.value)
sheet.cell_value(109,7)
'No' #序列转为单元格命名
cell = cellname(2,2)
print(cell)
C3
cell = cellnameabs(2,2)
print(cell)
$C$3
cell = colname(3)
print(cell)
python-excel操作之xlrd的更多相关文章
- python excel操作总结
1.openpyxl包的导入 Dos命令行输入 pip install openpyxl==2.3.3 这里注意一下openpyxl包的版本问题 版本装的太高有很多api不支持了,所以笔者这里用的是2 ...
- Python+Excel 操作对比
前言 从网页爬下来的大量数据需要excel清洗成堆的科学实验数据需要导入excel进行分析作为一名面向逼格的Python程序员该如何合理而又优雅的选择生产力工具呢? 得益于辛勤劳作的python大神们 ...
- python学习,excel操作之xlrd模块常用操作
import xlrd ##工作表## #打开excel f = xlrd.open_workbook("test.xlsx") file = f.sheet_by_name(&q ...
- Python Excel操作——xlrd、xlwd
读取 1.导入模块 import xlrd 2.打开Excel文件读取数据 data = xlrd.open_workbook('excel.xls') 3.获取一个工作表 1 table = dat ...
- python excel操作
python操作excel表格(xlrd/xlwt)转载:http://www.cnblogs.com/zhoujie/p/python18.html 最近遇到一个情景,就是定期生成并发送服务器使 ...
- Python Excel操作库
xlrd:支持.xls..xlsx读 xlwt:只支持.xls写 xlutils:只支持.xls读写 依赖于xlrd和xlwt xlwings:支持.xls读,.xlsx读写 可以实现Excel和Py ...
- Python Excel 操作
1.Excel Code import os import time import re import win32com.client def dealpath(pathname='') -> ...
- python excel操作 练习-#操作单列 #操作A到C列 #操作1到3行 #指定一个范围遍历所有行和列 #获取所有行 #获取所有列
##操作单列#操作A到C列#操作1到3行#指定一个范围遍历所有行和列#获取所有行#获取所有列 #coding=utf-8 from openpyxl import Workbook wb=Workbo ...
- python excel操作 练习:#生成一个excel文件,生成3个sheet,每个sheet的a1写一下sheet的名称。每个sheet有个底色
练习:#生成一个excel文件,生成3个sheet,每个sheet的a1写一下sheet的名称.每个sheet有个底色 #coding=utf-8 from openpyxl import Workb ...
- Python excel 库:Openpyxl xlrd 对比 介绍
打算用python做一个写mtk camera driver的自动化工具. 模板选用标准库里面string -> Template 即可 但要重定义替换字符,稍后说明 配置文件纠结几天:cfg, ...
随机推荐
- [BZOJ1858] [SCOI2010] 序列操作 解题报告 (线段树)
题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1858 Description lxhgww最近收到了一个01序列,序列里面包含了n个数, ...
- ViewPager设置不能滚动
设置ViewPager不能滑动 1:设置当前选中的页面 public void setCurrentItem(int item) { mPopulatePending = false; setCurr ...
- PostgreSQL Replication之第八章 与pgbouncer一起工作(4)
8.4 提升性能 从一开始考虑pgbouncer的时候,性能就是一个关键的因素.为了确保高性能,有些问题必须认真对待.首先,确保参与您设置的所有节点相互之间的距离较近.这对于降低网络往返时间有很多的帮 ...
- ipad mini2 升级9.0.2后解锁白屏解决
解锁白屏是个什么现象?就是当你用手指滑动解锁后出现输入密码的界面后,1秒之内屏幕变白,中间一个黑色的苹果,几秒之后重新回到滑动解锁的界面.我出现这个现象不是因为升级了9.0.2,而是升级了9.0.2之 ...
- html局部页面打印
1.局部打印函数. function preview(oper) { if (oper < 10) { bdhtml=window.document.body.innerHTML;//获取当前页 ...
- IBM主机上清除告警黄灯方法
机器亮黄灯告警一般是有硬件问题(单电源等可能有安全隐患的硬件配置也可能造成黄灯亮起),见到后首先进行下硬件诊断,方法如下: 诊断系统,判断是否硬件故障:1.Root用户执行diag: 2.回车后,进第 ...
- centos7 安装 Python netsnmp模块
由于模块的安装过程中有点艰难(其实挺简单,只是参照网上的教程很多都装不成功,花了很多时间...),所以记下来备忘. 先装一下python-devel 模块,执行命令 yum install pytho ...
- luoguP1419 寻找段落(二分答案+单调队列)
题意 给定一个长度为n的序列a1~an,从中选取一段长度在s到t之间的连续一段使其平均值最大.(n<=100000) 题解 二分答案平均值. judge时把每一个a[i]-mid得到b[i] 在 ...
- Windows10通过VNC远程连接Ubuntu18.04
1.打开终端输入:sudo apt-get install xrdp vnc4server xbase-clients dconf-editor 2.接着在终端输入: 进入到下面这个界面: 接着按照这 ...
- Vuex-一个专为 Vue.js 应用程序开发的状态管理模式
为什么会出现Vuex 非父子关系的组件如何进行通信?(Event Bus)bus.js import Vue from 'vue'; export default new Vue(); foo.vue ...