最近媳妇工作上遇到一个重复性劳动,excel表格查重,重复的标记起来,问我能不能写个程序让它自动查重标记
必须安排
第一次正儿八经写python,边上网查资料,边写
终于成功了
在此记录一下
- 首先安装
xlwings
库
pip install xlwings
- 写代码
import xlwings as xw
# 输入表名
title = input()
# 指定不显示地打开Excel,读取Excel文件
app = xw.App(visible=False, add_book=False)
wb = app.books.open(title) # 打开Excel文件
sheet = wb.sheets[0] # 选择第0个表单
# 获取表行数
sheetInfo = sheet.used_range
maxRow = sheetInfo.last_cell.row
# maxColumn = sheetInfo.last_cell.column
# print('表行数:',maxRow)
# 单据编号
num = []
# 报销类型
baoxiaoType = []
# 部门
department = []
# 收款方
name = []
# 报销金额
money = []
# 将需要的数据读取保存
for row in range(2, maxRow):
value = sheet.range("A" + str(row)).v