python之读取Excel 文件
# -*- coding: utf-8 -*-
"""
Created on Thu May 24 13:53:10 2018 @author: Frank
""" import xlrd #xlrd is a library for reading data and formatting information from Excel files, whether they are .xls or .xlsx files.
data = xlrd.open_workbook('通讯录.xlsx')#打开 Excel文件
print(type(data))
table = data.sheets()[0]
print(type(table))
nrows = table.nrows #行数
print("行数:{}".format(nrows))
ncols = table.ncols #列数
print("列数:{}".format(ncols))
for i in range(0,nrows):
rowValues = table.row_values(i) #某一行数据
#print(type(rowValues))
#print(rowValues)
print("姓名:{}<-->电话:{}".format(rowValues[0], rowValues[1]))
xlrd.open_workbook(filename=None, logfile=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, verbosity=0, use_mmap=1, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ragged_rows=False)
打开一个Excel文件。
这里先简单的介绍基本的参数,以后有用到再添加。
Parameters:
filename – The path to the spreadsheet file to be opened.
指定要打开文件的路径
logfile – An open file to which messages and diagnostics are written
Returns:
An instance of the Book class.
book.sheets()
Return: A list of all sheets in the book. 返回Excel中所有的表,并保存在list中。
All sheets not already loaded will be loaded.
classxlrd.sheet.Sheet(book, position, name, number)
Contains the data for one worksheet.
In the cell access functions, rowx is a row index, counting from zero, and colx is a column index, counting from zero. Negative values for row/column indexes and slice positions are supported in the expected fashion.
Note: You don’t instantiate this class yourself. You access Sheet objects via the Book object that was returned when you called xlrd.open_workbook().
nrows= 0
Number of rows in sheet. A row index is in range(thesheet.nrows).
ncols= 0
Nominal number of columns in sheet. It is one more than the maximum column index found, ignoring trailing empty cells. See also the ragged_rows parameter to open_workbook() and row_len().
row_values(rowx, start_colx=0, end_colx=None)
Returns a slice of the values of the cells in the given row.该函数返回一个list,默认包含这一行的cells的所有内容。
python之读取Excel 文件的更多相关文章
- python下读取excel文件
项目中要用到这个,所以记录一下. python下读取excel文件方法多种,用的是普通的xlrd插件,因为它各种版本的excel文件都可读. 首先在https://pypi.python.org/py ...
- python xlrd读取Excel文件
1 import xlrd 2 3 #打开excel文件 4 book = xlrd.open_workbook('salary.xls') 5 6 #打印每个工作表的名称 7 for sheet i ...
- python读取excel文件
一.xlrd的说明 xlrd是专门用来在python中读取excel文档的模块,使用前需要安装. 可以到这https://pypi.python.org/pypi/xlrd进行下载tar.gz文件,然 ...
- 记录:python读取excel文件
由于最近老是用到python读取excel文件,所以特意记录一下python读取excel文件的大体框架. 库:xlrd(读),直接pip安装即可.想要写excel文件的话,安装xlwd库即可,也是直 ...
- 用python的pandas读取excel文件中的数据
一.读取Excel文件 使用pandas的read_excel()方法,可通过文件路径直接读取.注意到,在一个excel文件中有多个sheet,因此,对excel文件的读取实际上是读取指定文件.并 ...
- python脚本 读取excel格式文件 并进行处理的方法
一.安装xlrd模块 pip install xlrd 二.读取excel文件 try: excel_obj = xlrd.open_workbook("文件路径") except ...
- 第一节:python读取excel文件
写在前面: (1)Excel中数字格式int(1),读出的是float(1.0)类型,导致传参时造成不同,强制转换时,int(str(1.0))在2.7版本又会报错ValueError: invali ...
- python:创建文件夹:写入文本1:读取txt:读取Excel文件遍历文件夹:
https://blog.csdn.net/u011956147/article/details/80369731 创建文件夹: import osimport shutil def buildfil ...
- Python使用读写excel文件
Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...
随机推荐
- Oracle 11gR2 RAC 数据库不能连接(ORA-12537: TNS:connection closed)的解决
Oracle 11gR2 RAC 数据库不能连接(ORA-12537: TNS:connection closed)的解决 [oracle@rac01 ~]$ sqlplus /nolog S ...
- Oracle数据库查看用户状态
一.当前ORACLE用户的状态可查看视图DBA_USERS;一般情况下在使用的正常用户均处于OPEN状态. 1 SQL> select username,account_status from ...
- 查看iOS Crash logs
当应用在设备中运行发生崩溃,iOS将记录这些错误日志并且创建了崩溃报告(Crash Report).崩溃报告中包含了iOS的版本.日期.异常类型.堆栈跟踪以及其他信息. ① 在Xcode中查看崩溃报告 ...
- [转]SSIS包的调用方式
本文转自:http://www.cnblogs.com/lijun4017/archive/2008/12/04/1347701.html 编写简单SSIS包光看MSDN应该就问题不大了,最近几天几个 ...
- python3将docx转换成pdf,html文件,pdf转doc文件
直接上代码 # -*- encoding:utf-8 -*- """ author:lgh 简单的doc转pdf,html,pdf转doc脚本 依赖库pdfminer3k ...
- 解决安装mysqlclient出现问题:mysql_config: not found
解决安装mysqlclient出现如下问题: Complete output from command python setup.py egg_info: /bin/sh: : mysql_confi ...
- 在移动网页网页上点击链接跳转到QQ聊天界面
打开qq聊天窗口的方法 <a href="http://wpa.qq.com/msgrd?v=3&uin=1450612626&site=qq&menu=yes ...
- OpenCV 之 霍夫变换
Hough 变换,对图像中直线的残缺部分.噪声.以及其它的共存结构不敏感,因此,具有很强的鲁棒性. 它常用来检测 直线和曲线 (圆形),识别图像中的几何形状,甚至可用来分割重叠或有部分遮挡的物体. 1 ...
- App服务端架构变迁
随着移动互联网时代的到来,移动技术也随之飞速发展.如今,App已然成为绝大多数互联网企业用来获取用户的核心渠道.以往以PC为主要承载平台的各业务线,源源不断集成加入到移动项目中来,原本以产品为中心快速 ...
- C/C++中传值和传地址(引用)
C/C++中参数传递有两种方式,传值或传地址(传引用),通常我们要在被调用函数中改变一个变量的值就需要传地址调用方式,例如: void swap_by_value(int a, int b) { in ...