[python](4)-----excel操作

excel表格操作

1. 登陆(加密,锁定账户)
2. 图书查看
3. 添加图书信息
4. 修改
5. 删除(软删除)

import xlrd
def login(username,password):
    #加密
    #验证
    book = xlrd.open_workbook("e://person.xls")
    # sheet1 = book.sheet_by_index(0)
    sheet1 = book.sheet_by_name("person")
    # a = sheet1.cell(2,3).value
    # 一共多少行
    r = sheet1.nrows
    # 一共多少列
    c = sheet1.ncols
    flag = False
    for i in range(1, r):
        if username == sheet1.cell(i,1).value and password == sheet1.cell(i,2).value:
            flag = True
            break
    return flag
import getpass
a = getpass.getpass("请输入密码:")
print(a)
import xlrd
book = xlrd.open_workbook("e://person.xls")
#sheet1 = book.sheet_by_index(0)
sheet1 = book.sheet_by_name("person")
#a = sheet1.cell(2,3).value
#一共多少行
r = sheet1.nrows
#一共多少列
c = sheet1.ncols
for i in range(1,r):
    for j in range(c):
        print(sheet1.cell(i,j).value,end=" ")
    print()
import xlrd,xlwt
from xlutils import copy

book = xlrd.open_workbook("e://person.xls")
book_copy = copy.copy(book)
sheet = book_copy.get_sheet(0)
sheet.write(2,1,"霍金旭")
book_copy.save("e://person.xls")

import xlrd,xlwt
from xlutils import copy

book = xlrd.open_workbook("e://person.xls")
r = book.sheet_by_name("person").nrows
c = book.sheet_by_name("person").ncols
book_copy = copy.copy(book)
sheet = book_copy.get_sheet(0)

a = ["3","张三","18","147","男","0"]
for i in range(c):
    sheet.write(r,i,a[i])

book_copy.save("e://person.xls")
import xlwt
#只能写不能读
stus = [['姓名', '年龄', '性别', '分数'],
         ['mary', 20, '女', 89.9],
         ['mary', 20, '女', 89.9],
         ['mary', 20, '女', 89.9],
         ['mary', 20, '女', 89.9]
         ]
book = xlwt.Workbook()#新建一个excel
sheet = book.add_sheet('case1_sheet')#添加一个sheet页
row = 0#控制行
for stu in stus:
     col = 0#控制列
     for s in stu:#再循环里面list的值,每一列
         sheet.write(row,col,s)
         col+=1
     row+=1
book.save('stu_1.xls')#保存到当前目录下
import xlwt
book = xlwt.Workbook()
sheet = book.add_sheet("user")
sheet.write(2,2,"nihao")
book.save("e://user.xls")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值