pythone函数基础(11)读,写,修改EXCEL
#读EXCEL需要导入xlrd模块---在python控制台pip install xlrd模块
import xlrd
book = xlrd.open_workbook('stu3.xls')
sheet = book.sheet_by_index(0)
# sheet = book.sheet_by_name('sheet1')
# print(sheet.cell(0,0).value)#获取指定单元格的内容
# print(sheet.cell(1,0).value)
# print(sheet.row_values(0)) #获取整行的数据
# print(sheet.row_values(1))
# print(sheet.col_values(0))#获取整列的数据
# print(sheet.col_values(1)) print(sheet.nrows) #行数
print(sheet.ncols) #列数
for row in range(1,sheet.nrows):
print(sheet.row_values(row)) 写EXCEL需要导入 import xlwt -----在python控制台pip install xlwt模块
import xlwt
book = xlwt.Workbook() #新建一个excel
sheet = book.add_sheet('sheet1') #添加一个sheet页 # sheet.write(0,0,'编号')
# sheet.write(0,1,'名字')
# sheet.write(0,2,'性别')
#
# sheet.write(1,0,'1')
# sheet.write(1,1,'马春波')
# sheet.write(1,2,'男') stu_info = [
['编号','姓名','密码','性别','地址'],
[1,'machunbo','sdfsd23sdfsdf2','男','北京'],
[2,'machunbo2','sdfsd23sdfsdf2','男','北京'],
[3,'machunb3','sdfsd23sdfsdf2','男','北京'],
[4,'machunbo4','sdfsd23sdfsdf2','男','北京'],
[5,'machunbo5','sdfsd23sdfsdf2','男','北京'],
[6,'machunbo6','sdfsd23sdfsdf2','男','北京'],
[7,'machunbo6','sdfsd23sdfsdf2','男','北京'],
[8,'machunbo6','sdfsd23sdfsdf2','男','北京'],
[9,'machunbo6','sdfsd23sdfsdf2','男','北京'],
[10,'machunbo6','sdfsd23sdfsdf2','男','北京'],
[11,'machunbo6','sdfsd23sdfsdf2','男','北京'],
]
#6行5列
# row = 0 #行
# for stu in stu_info:
# sheet.write(row,0,stu[0])
# sheet.write(row,1,stu[1])
# sheet.write(row,2,stu[2])
# sheet.write(row,3,stu[3])
# sheet.write(row,4,stu[4])
# row+=1 # row = 0 #行
# for stu in stu_info:
# #stu
# col = 0 # 列
# # [1, 'machunbo', 'sdfsd23sdfsdf2', '男', '北京'],
# for s in stu: #控制列
# sheet.write(row,col,s) #0 3 男
# col+=1
# row+=1 for index,value in enumerate(stu_info):
# index 0
# value ['编号','姓名','密码','性别','地址'] #index 1
#value [1,'machunbo','sdfsd23sdfsdf2','男','北京']
for index2,v2 in enumerate(value):
print(index,index2,v2)
#0 1
#1 machunbo
#2 sdfsd23sdfsdf2
#4 北京
sheet.write(index,index2,v2) book.save('stu3.xls') #wps xls xlsx ,微软的office xls
修改EXCEL,需要import xlutils-----在python控制台pip install xlwt模块
import xlrd
from xlutils import copy #1、先打开原来的excel
#2、复制一份
#3、在复制的excel上修改
#4、保存 book = xlrd.open_workbook('stu3.xls')
new_book = copy.copy(book) #
sheet = new_book.get_sheet(0) #修改excel的时候,得用get_sheet()
sheet.write(0,0,'id')
sheet.write(0,3,'password')
new_book.save('stu3.xls')
pythone函数基础(11)读,写,修改EXCEL的更多相关文章
- Pandas 基础(4) - 读/写 Excel 和 CSV 文件
这一节将分别介绍读/写 Excel 和 CSV 文件的各种方式: - 读入 CSV 文件 首先是准备一个 csv 文件, 这里我用的是 stock_data.csv, 文件我已上传, 大家可以直接下载 ...
- pythone函数基础(12)连接Redis,写数据,读数据,修改数据
需要导入Resdis模块 import redisip = '127.0.0.1'password='123456'r = redis.Redis(host=ip,password=password, ...
- pythone函数基础(8)内置函数学习
内置函数学习# sorted# map# filter# max# sum# round# chr# ord# dir# bool# eval# exec# zipimport mathres = m ...
- pythone函数基础(7)第三方模块学习
一,time模块学习 import time # print(int(time.time()))#时间戳# res = time.strftime('%Y-%m-%d %H:%M:%S')#取当前格式 ...
- pythone函数基础(15)接口开发初识
导入需要的第三方模块 import flaskimport toolsimport json,redisimport random server = flask.Flask(__name__)#新建一 ...
- pythone函数基础(14)发送邮件
导入yagmail模块import yagmailusername='uitestp4p@163.com'password='houyafan123'#生成授权码,qq.163.126都是授权码 ma ...
- pythone函数基础(13)发送网络请求
需要导入urllib模块,request模块发送网络请求有两种方法 第一种方法# from urllib.request import urlopen# from urllib.parse impor ...
- pythone函数基础(10)MD5加密
导入hashlib模块import hashlibs='yulin123456's.encode()#把数字转换成bytes类型m=hashlib.md5(s.encode())print(m.hex ...
- pythone函数基础(9)操作数据库连接
#操作数据库连接import pymysqlconn = pymysql.connect(host='118.24.3.40',user='jxz', password='123456',port=3 ...
随机推荐
- 修改Linux主机名
如果安装时没有设置,一般默认主机名为localhost.localdomain. 通过以下方式修改成自己设置的主机名: 1. vi /etc/sysconfig/network NETWORKING= ...
- idhttp采集时遇到乱码问题解决
关键部分代码: FIdhttp.Request.Referer := SQL; stream := TStringStream.Create(''); stream.Position := 0; FI ...
- alpha阶段发布博客
我们的Phylab网站发布了! Alpha版本功能 模块 功能 注册界面 根据邮箱,学号等信息注册新用户 登陆界面 根据账号信息登陆 用户界面 查看,修改用户信息和签名 实验报告界面 查看各个实验预习 ...
- 如何快速扫描C段(网站快照、后台识别/登录、目录扫描)
1.C段扫描 C类地址范围从 192.0.0.1 到 223.255.255.254 ,192转换成二进制就是1100000:223转换成二进制就是1101111:所以说网络地址的最高位肯定是110开 ...
- 如何解决button,a,input标签自带蓝色边框
通常我们会设置该标签outline:0;但是我在使用iview自带的button组件的时候,设置无效,经过测试只要设置 :focus{ outline:0; } 即可,方便有效
- supersocket 遇到的Failed to initialize 和 log4net用法
使用Bootstrap来通过配置启动SuperSocket的时候总是显示Failed to initialize! , 官网配置中 <superSocket> <servers&g ...
- 常用LINUX命令汇总
一.基本命令bash Bash(GNU Bourne-Again Shell)是许多Linux平台的内定Shellpwd 查看当前所在目录ls 查看目录内所有文件cd 进入目录cd .. 返回上一层p ...
- 【HDFS API编程】副本系数深度剖析
上一节我们使用Java API操作HDFS文件系统创建了文件a.txt并写入了hello hadoop(回顾:https://www.cnblogs.com/Liuyt-61/p/10739018.h ...
- redis hashmap数据结构分析
说明一点:redis的hash中每一个key都是一个单独的hash表,field是hash表中的key,value是hash表中的value: //redis中hash数据结构为:key-field- ...
- ffplay流程分析
void main() { is = stream_open(input_filename, file_iformat); } static VideoState *stream_open(const ...