python读取xls文件

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/10/17 14:41
# @Author  : Sa.Song
# @Desc    :
# @File    : read_xls.py
# @Software: PyCharm
import sys
from xlrd import open_workbook # xlrd用于读取xld
import xlwt  # 用于写入xls
workbook = open_workbook(r‘C:\Users\songsa\Desktop\maoyan_comment.xls‘)  # 打开xls文件
sheet_name= workbook.sheet_names()  # 打印所有sheet名称,是个列表
sheet = workbook.sheet_by_index(0)  # 根据sheet索引读取sheet中的所有内容
sheet1= workbook.sheet_by_name(‘Sheet1‘)  # 根据sheet名称读取sheet中的所有内容
print(sheet.name, sheet.nrows, sheet.ncols)  # sheet的名称、行数、列数
content = sheet.col_values(7)  # 第六列内容
print(content)

原文地址:https://www.cnblogs.com/ss-py/p/9804696.html

时间: 2024-08-01 02:24:34

python读取xls文件的相关文章

python读取excel文件(xrld模块)

Python读取excel文件 一.python  xlrd模块 安装 mac 下安装python  xlrd模块 http://www.crifan.com/python_read_excel_xls_file_xlrd/comment-page-1/ python setup.py install 在mac 下出现的错误是 http://stackoverflow.com/questions/18199853/error-could-not-create-library-python-2-7

python 读取 excel文件

python读取excel文件的链接都是从这里获取的: http://blog.csdn.net/longshen747/article/details/17194259 http://www.cnblogs.com/yanzhi123/archive/2012/04/16/2452214.html 上个示例的代码: import xml.etree.ElementTree as ETimport xlwtimport os path = "D:/Cai_Bishe/xml/"prin

python 读取excel文件

1.用python读取csv文件: csv是逗号分隔符格式 一般我们用的execl生成的格式是xls和xlsx  直接重命名为csv的话会报错: Error: line contains NULL byte insun解决方案:出错原因是直接是把后缀为xls的execl文件重命名为csv的 正常的要是另存为csv文件 就不会报错了 譬如我们有这么个csv文件: #!/usr/bin/env python # -*- coding:utf-8 -*-   import csv with open(

Python读取txt文件

Python读取txt文件,有两种方式: (1)逐行读取 1 data=open("data.txt") 2 line=data.readline() 3 while line: 4 print line 5 line=data.readline() (2)一次全部读入内存 1 data=open("data.txt") 2 for line in data.readlines(): 3 print line

Python读取Yaml文件

近期看到好多使用Yaml文件做为配置文件或者数据文件的工程,随即也研究了下,发现Yaml有几个优点:可读性好.和脚本语言的交互性好(确实非常好).使用实现语言的数据类型.有一个一致的数据模型.易于实现. 既然有这么多好处,为什么不用呢,随后开始研究在Python中怎么读取Yaml文件,下面我们来看下: 1.首先需要下载Python的yaml库PyYAML,下载地址:http://pyyaml.org/,安装过程就省略...... 2.建立一个.py文件 3.import yaml 4.f = o

Python读取SQLite文件数据

近日在做项目时,意外听说有一种SQLite的数据库,相比自己之前使用的SQL Service甚是轻便,在对数据完整性.并发性要求不高的场景下可以尝试! 1.SQLite简介: SQLite是一个进程内的库,实现了自给自足的.无服务器的.零配置的.事务性的 SQL 数据库引擎.它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它(如安卓系统),它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了.它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多

python读取中文文件编码问题

python 读取中文文件后,作为参数使用,经常会遇到乱码或者报错asii错误等. 我们需要对中文进行decode('gbk') 如我有一个data.txt文件有如下内容: 百度 谷歌 现在想读取文件中内容构建查询语句代码如下: f=open('data.txt','r') for i in f.readlines(): data_line=i.strip() data=data_line.decode("gbk") print "this is %s"%data

Python 读取 excel 文件

现在大部分数据都是存储在excel中或直接调取数据库,作为刚刚自学Python的小白来说怎么读取文件还是比较懵的,现在对Python读取excel文件进行了一些整理: #coding=utf-8 #cmd中进行安装xlrd库 pip install xlrd import xlrd #文件路径,要用/而不是\ file_path = r'C:/Users/mingli.zhao/Desktop/七天.xlsx' #中文转码 #file_path = file_path.decode('utf-8

使用python读取yaml文件

在做APP测试时,通常需要把参数存到一个字典变量中,这时可以将参数写入yaml文件中,再读取出来. 新建yaml文件(android_caps.yaml),文件内容为: 1 platformName: Android 2 platformVersion: '5.1' 3 deviceName: Android Emulator 4 appPackage: com.xx.xx 5 appActivity: com.xx.xx.activity.WelcomeActivity python读取yam