#读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的更多相关文章

  1. Pandas 基础(4) - 读/写 Excel 和 CSV 文件

    这一节将分别介绍读/写 Excel 和 CSV 文件的各种方式: - 读入 CSV 文件 首先是准备一个 csv 文件, 这里我用的是 stock_data.csv, 文件我已上传, 大家可以直接下载 ...

  2. pythone函数基础(12)连接Redis,写数据,读数据,修改数据

    需要导入Resdis模块 import redisip = '127.0.0.1'password='123456'r = redis.Redis(host=ip,password=password, ...

  3. pythone函数基础(8)内置函数学习

    内置函数学习# sorted# map# filter# max# sum# round# chr# ord# dir# bool# eval# exec# zipimport mathres = m ...

  4. pythone函数基础(7)第三方模块学习

    一,time模块学习 import time # print(int(time.time()))#时间戳# res = time.strftime('%Y-%m-%d %H:%M:%S')#取当前格式 ...

  5. pythone函数基础(15)接口开发初识

    导入需要的第三方模块 import flaskimport toolsimport json,redisimport random server = flask.Flask(__name__)#新建一 ...

  6. pythone函数基础(14)发送邮件

    导入yagmail模块import yagmailusername='uitestp4p@163.com'password='houyafan123'#生成授权码,qq.163.126都是授权码 ma ...

  7. pythone函数基础(13)发送网络请求

    需要导入urllib模块,request模块发送网络请求有两种方法 第一种方法# from urllib.request import urlopen# from urllib.parse impor ...

  8. pythone函数基础(10)MD5加密

    导入hashlib模块import hashlibs='yulin123456's.encode()#把数字转换成bytes类型m=hashlib.md5(s.encode())print(m.hex ...

  9. pythone函数基础(9)操作数据库连接

    #操作数据库连接import pymysqlconn = pymysql.connect(host='118.24.3.40',user='jxz', password='123456',port=3 ...

随机推荐

  1. 并发之痛 Thread,Goroutine,Actor

    转自:http://jolestar.com/parallel-programming-model-thread-goroutine-actor/ 先梳理下两个概念,几乎所有讲并发的文章都要先讲这两个 ...

  2. winform界面特效470多例

    一共470多例winform 界面特效的源码. 实例030 窗口颜色的渐变 实例说明 在程序设计时,可以通过设置窗体的BackColor属性来改变窗口的背景颜色.但是这个属性改变后整个窗体的客户区都会 ...

  3. [STM31F103]独立看门狗

    独立看门狗步骤: l 取消寄存器写保护: n IWDG_WriteAccessCmd(); l 设置独立看门狗的预分频系数,确定时钟: n IWDG_SetPrescaler(); l 设置看门狗重装 ...

  4. hive动态分区问题--分区为中文

    报错如下: Loading data to table data_da.tmp_wlw_test partition (stat_date=2017-05-11, business_type_name ...

  5. 分享一个Snackbar工具类 SnackbarUtils;

    分享一个Snackbar工具类,源代码也是在Github上面找的,自己做了一下修改: 功能如下: 1:设置Snackbar显示时间长短                 1.1:Snackbar.LEN ...

  6. sql语句case when 以及left()

    select count(CASE jyje WHEN '1300' THEN '2' ELSE '1' END) as count  from tpent_orders where cplx = 6 ...

  7. python-web自动化-键盘操作

    selenium提供了较为完整的键盘操作引入 from selenium.webdriver.common.keys import Keys使用键盘操作时,需要借助send_keys()来模拟操作.K ...

  8. AET PN结

    电场方向 电场方向和正电荷受力方向相同 飘移运动和扩散运动 多子和电场方向互相抵制,而多子是扩散运动,而对少子则是促进作用,当扩散和漂移达到动态平衡时,我们称PN结形成 PN结特性 单项导电性

  9. 从 注解和继承 到 JAXB中的注意事项

    从 注解和继承 到 JAXB中的注意事项 注解在继承中的行为 如果一个父类添加了一个注解,子类是否能取到这个注解呢?如下 package inheritance; import java.lang.a ...

  10. TCP协议-连接建立和释放

    三次握手: (1)客户端向服务器端TCP请求连接,向服务器端发送控制位SYN=1,序号seq=x的请求报文.(x是随机产生的,且不能为0) (2)服务器端接收到请求报文后,若同意建立连接,则向客户端发 ...