# -*- 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=Nonelogfile=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>verbosity=0use_mmap=1file_contents=Noneencoding_override=Noneformatting_info=Falseon_demand=Falseragged_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(bookpositionnamenumber)

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(rowxstart_colx=0end_colx=None)

  Returns a slice of the values of the cells in the given row.该函数返回一个list,默认包含这一行的cells的所有内容。

python之读取Excel 文件的更多相关文章

  1. python下读取excel文件

    项目中要用到这个,所以记录一下. python下读取excel文件方法多种,用的是普通的xlrd插件,因为它各种版本的excel文件都可读. 首先在https://pypi.python.org/py ...

  2. python xlrd读取Excel文件

    1 import xlrd 2 3 #打开excel文件 4 book = xlrd.open_workbook('salary.xls') 5 6 #打印每个工作表的名称 7 for sheet i ...

  3. python读取excel文件

    一.xlrd的说明 xlrd是专门用来在python中读取excel文档的模块,使用前需要安装. 可以到这https://pypi.python.org/pypi/xlrd进行下载tar.gz文件,然 ...

  4. 记录:python读取excel文件

    由于最近老是用到python读取excel文件,所以特意记录一下python读取excel文件的大体框架. 库:xlrd(读),直接pip安装即可.想要写excel文件的话,安装xlwd库即可,也是直 ...

  5. 用python的pandas读取excel文件中的数据

    一.读取Excel文件   使用pandas的read_excel()方法,可通过文件路径直接读取.注意到,在一个excel文件中有多个sheet,因此,对excel文件的读取实际上是读取指定文件.并 ...

  6. python脚本 读取excel格式文件 并进行处理的方法

    一.安装xlrd模块 pip install xlrd 二.读取excel文件 try: excel_obj = xlrd.open_workbook("文件路径") except ...

  7. 第一节:python读取excel文件

    写在前面: (1)Excel中数字格式int(1),读出的是float(1.0)类型,导致传参时造成不同,强制转换时,int(str(1.0))在2.7版本又会报错ValueError: invali ...

  8. python:创建文件夹:写入文本1:读取txt:读取Excel文件遍历文件夹:

    https://blog.csdn.net/u011956147/article/details/80369731 创建文件夹: import osimport shutil def buildfil ...

  9. Python使用读写excel文件

    Python使用openpyxl读写excel文件 这是一个第三方库,可以处理xlsx格式的Excel文件.pip install openpyxl安装.如果使用Aanconda,应该自带了. 读取E ...

随机推荐

  1. Struct2_定义拦截器并使用注解方式作用在Action的方法中

    一.目的:通过在方法上加注解控制哪些方法需要登陆后才能访问   二.方式:利用拦截器判断用户是否登陆   三.实现步骤 定义配置文件struts.xml添加节点 1 2 3 4 5 6 7 8 9 1 ...

  2. Openshift部署Zookeeper和Kafka

    部署Zookeeper github网址 https://github.com/ericnie2015/zookeeper-k8s-openshift 1.在openshift目录中,首先构建imag ...

  3. TCP三次握手连接和TCP四次挥手及大量TIME_WAIT解决方法:

    1.TCP建立连接,三次握手 建立的TCP连接可靠的连接,必须经过三次握手建立连接才能正式通信彼此传输数数据. 客户端请求服务端建立连接 第一次握手:客户给服务发送一个请求报文SYN, 客户端的状态置 ...

  4. python对于0x01的处理

    对于python脚本,可以使用: .replace('\x01', '') 对于vim工具,可以使用: :%s/\%x01/ /g

  5. redhat6.3 找不到libXP.so.6解决方法

    最近做redhat安装matlab2008a 操作,遇到上面的问题,先记录如下: 网上找到安装包:libXp-1.0.2-1mamba.x86_64.rpm 然后使用命令: sudo rpm -ivh ...

  6. POJ 1844 Sum【简单数学】

    链接: http://poj.org/problem?id=1844 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=29256#probl ...

  7. java线程总结(1/5)

    前言 闲来无事正值面试,看面试中有线程之问题,特此总结一番. 正文 一.线程和进程的区别:1.每个进程都有独立的代码和数据空间(进程上下文),进程间的切换会有较大的开销.2.线程可以看成时轻量级的进程 ...

  8. dubbo-monitor安装监控中心,管理控制台安装网页一直访问不到,解决bug的方式记录

    问题再现 第一步,重启机器 第二步,按照dubbo-monitor需要开启的服务,顺序逐一进行启动,之前的推翻全部重新再走一遍就通了,千万不能死磕...很浪费时间.... 通过打印日志追踪问题的所在. ...

  9. Coursera-Algotithms学习

    Week1 Job Interview Question Social network connectivity. Given a social network containing N member ...

  10. 【DB2】NVL2函数

    语法: NVL2(表达式1,表达式2,表达式3) 如果表达式1为空,返回值为表达式3的值.如果表达式1不为空,返回值为表达式2的值. 例子: SELECT ID, NVL2(SEX,'非空','空值' ...