Python-xlutils

xlutils是python中修改excel的库,xlrd是python中读取excel的库,xlwt是python中写入excel的库,这三个库的使用方法都是一样的,都是先打开excel,然后对excel进行操作,最后保存excel。下面是xlutils的使用方法。

xlutils的安装:pip install xlutils

1.筛选出列中的某个值

import xlrd
from xlutils.copy import copy

# 打开excel文件读取数据
data = xlrd.open_workbook('test.xlsx')
# 复制excel文件
workbook = copy(data)
# 获取sheet
sheet = workbook.get_sheet(0)

# 筛选出列中的某个值
col_values = sheet.col_values(0)
col_values = [i for i in col_values if i == 'test']

2.替换单元格的值

# 替换单元格的值
sheet.put_cell(0, 0, 1, 'test', 0)

3.对某一列进行排序

# 对某一列进行排序
sheet.sort(0, 0, 1)

4.保存excel

# 保存excel
workbook.save('test.xlsx')
posted @ 2023-05-25 09:47  Fanslyx  阅读(258)  评论(0)    收藏  举报