pythonopenpyxl 删除excel 中列值所在的⾏
删除excel中列为特定值的所有⾏# 导⼊需要⽤到的相关包import os import openpyxl #定义删除函数def delete_row (filename , sheet_name , exc_string , column_num ): # 载⼊⼯作簿 wb = openpyxl .load_workbook (filename ) print ('excel have been opened') # open the sheet ws = wb [sheet_name ] print ('use the sheet') for i in range (1, ws .max_row , 1): #从第⼀⾏开始到最后⼀⾏逐⾏进⾏ # print("go the for") # print(ws.max_row) # ll(row=i, column=column_num).value) if ws .cell (row =i , column =column_num ).value == exc_string : #如果该⾏第column_num 列值为'exc_string' print (i ) ws .delete_rows (i ,1) #则删除该⾏ print ('删除第-',i ,'-⾏成功!') wb .save (filename ='Update.xlsx')path = os .getcwd ()filename = 'Result1.xlsx'sheet_name = 'FinalData'exc_string = 'Sheet3'column_num = 2delete_row (filename , sheet_name , exc_string , column_num )1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
python怎么读取excel某一列
28
29
30
31
32
33
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论