python 操作excel
操作excel安装的三种方式:
1、pip instaill xlwt #写excel
pip instaill xlrd #读excel
pip instaill xlutils #修改excel
2、.whl
pip instail c:/user/niuhanyang/desktop/xxx.whl
3、.tar.gz
1、先解压
2、解压之后在命令行里面进入到这个目录下
3、执行python setup.py install
4、如果安装多个python版本
python3.5 -m pip instaill XXX
python2 -m pip instail XXX
python3.6 -m pip instail XXX
一、写excel
import xlwt
import xlrd
import xlutils # 写excel
book=xlwt.Workbook()
sheet=book.add_sheet('sheet1')
# sheet.write(0,0,'id') #指定行和列内容
# sheet.write(0,1,'username')
# sheet.write(0,2,'password')
#
# sheet.write(1,0,'1')
# sheet.write(1,1,'niuhanyang')
# sheet.write(1,2,'123456') stus=[
[1,'njf',''],
[2,'njf1',''],
[3,'njf2',''],
[4,'njf3',''],
[5,'njf4',''],
[6,'njf5',''],
[7,'njf6',''],
[8,'njf7',''],
[9,'njf8',''],
[10,'njf9',''],
]
line=0 #控制的是行
for stu in stus:
col=0
for s in stu:
sheet.write(line,col,s)
col+=1
line+=1 book.save('stu.xls')
二、读excel
import xlrd
book=xlrd.open_workbook('stu.xls')
sheet=book.sheet_by_index(0) #根据sheet编号来
# sheet=book.sheet_by_name('sheet1') #根据 sheet名称来
print(sheet.nrows) #excel里面有多少行
print(sheet.ncols) #excel里面有多少列
print(sheet.cell(0,0).value) #获取第0行第0列的值
print(sheet.row_values(0)) #获取到整行的内容
print(sheet.col_values(0)) #获取到整列的内容
for i in range(sheet.nrows): #循环获取每行的内容
print(sheet.row_values(i))
三、修改excel
import xlrd
import xlutils from xlutils import copy #xlutils中导入copy book=xlrd.open_workbook('stu.xls')
#先用xlrd打开一个excel
new_book=copy.copy(book)
#然后用xlutils里面的copy功能,复制一个excel sheet=new_book.get_sheet(0) #获取sheet页 sheet.write(0,1,'张三') #修改第0行,第一列
sheet.write(1,1,'小军') #修改第一行,第一列
new_book.save('stu.xls')
python 操作excel的更多相关文章
- python操作excel表格(xlrd/xlwt)
最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异,而且不太能满足需求,不过经过一番对源码的"研究&q ...
- Python操作Excel
一.系统性学习 对于操作Excel,需要Xlrd/xlwt这两个模块,下面推荐出系统性学习的网址: python操作Excel读写--使用xlrd 官方文档 Python 使用 Xlrd/xlwt 操 ...
- Python操作excel(xlrd和xlwt)
Python操作excel表格有很多支持的库,例如:xlrd.xlwt.openpyxl.win32com,下面介绍使用xlrd.xlwt和xlutils模块这三个库不需要其他的支持,在任何操作系统上 ...
- Python操作excel表格
用Python操作Excel在工作中还是挺常用的,因为毕竟不懂Excel是一个用户庞大的数据管理软件 注:本篇代码在Python3环境下运行 首先导入两个模块xlrd和xlwt,xlrd用来读取Exc ...
- Python 利用Python操作excel表格之openyxl介绍Part2
利用Python操作excel表格之openyxl介绍 by:授客 QQ:1033553122 欢迎加入全国软件测试交流qq群(群号:7156436) ## 绘图 c = LineChart() ...
- Python 利用Python操作excel表格之openyxl介绍Part1
利用Python操作excel表格之openyxl介绍 by:授客 QQ:1033553122 欢迎加入全国软件测试交流qq群(群号:7156436),免费获取以下性能监控工具(类似Nmon精简版) ...
- 【转】python操作excel表格(xlrd/xlwt)
[转]python操作excel表格(xlrd/xlwt) 最近遇到一个情景,就是定期生成并发送服务器使用情况报表,按照不同维度统计,涉及python对excel的操作,上网搜罗了一番,大多大同小异, ...
- Python 利用Python操作excel表格之xlwt介绍
利用Python操作excel表格之xlwt介绍 by:授客 QQ:1033553122 直接上代码 案例1 #!/usr/bin/env python # -*- coding:utf-8 ...
- Python 操作Excel之通过xlutils实现在保留原格式的情况下追加写入数据
在Python操作Excel 的模块有 xlrd.xlwt.xlutils等. xlrd:读取Excel文件数据 xlwt:写入Excel 数据,缺点是Excel格式无法复用,为了方便用户,写入的话, ...
- python基础(六)python操作excel
一.python操作excel,python操作excel使用xlrd.xlwt和xlutils模块,xlrd模块是读取excel的,xlwt模块是写excel的,xlutils是用来修改excel的 ...
随机推荐
- 解决虚拟机centos7 无法无法上网问题
centos无法上网问题 虚拟机设置 网段设置 网关设置 查看本地电脑设置 登录服务器设置 /etc/sysconfig/network-scripts/ 下面的 ifcfg-ens33 文件操 ...
- 2018-计算机系机试-A
#include<stdio.h> #include<cstdio> #include<cmath> #include<cstring> #includ ...
- time模块(时间)
time.time() #返回当前时间的时间戳 time.sleep() #CPU休息时间 print(time.clock()) #计算CPU执行时间 time.gmtime() #结构化时间 UT ...
- 微软连续12年成为Gartner分析和BI平台魔力象限的领导者
小悦还沉浸在新春开工大吉的工作中,微软Power BI就又迎来了一个好消息!据Gartner刚新鲜出炉的< 2019年Gartner的分析和商业智能平台魔力象限报告>,微软迄今已连续12 ...
- pyCharm django 中新加app
1.在manage.py@djangotest中输入命令: 1.startapp realnameauth ---新建一个app,名字为realnameauth 2.在 django 项目中的 ...
- Spring @EventListener 异步中使用condition的问题
@EventListener是spring在4.2+推出的更好的使用spring事件架构的方式,并且异步方式也很好设定 但是在spring4.2.7版本上使用eventlistener的conditi ...
- Go获取美元实时汇率
package main import ( "encoding/json" "fmt" "io/ioutil" "net/http ...
- 手机连接fiddler之后,安装证书的方法
1. 手机设置锁屏密码2. 手机连接fiddler测试网络3. 手机访问 电脑IP:fiddler设置的端口号4. 点击页面中的链接,下载并安装证书,随意命名即可 (还不清楚证书有啥用,先记录下 ...
- vue 使用canvas仿芝麻分信用表
如图所示: 画布组件:dashboard.vue <template> <div> <canvas ref="canvas" v-if="c ...
- JavaWeb(二)
三.搭建JavaWeb应用开发环境——Tomcat服务器 3.1.疑问:学习web开发,为什么必须要先装一个WEB服务器? 在本地计算机上随便创建一个web页面,用户是无法访问到的,但是如果启动tom ...