别人的需求,一个小脚本、
代码如下:
import openpyxl
# 打开 Excel 文件
path = r'D:\Paper\data_late.xlsx'
workbook = openpyxl.load_workbook(path)
# 获取第一个工作表
worksheet = workbook.active
# 获取字符串列的值,并将其转换为列表
strings = [cell.value for cell in worksheet["B"]] # 列表
# print(strings)
# exit()
# 打开文本文件并读取每一行
with open('keyword_list.txt', 'r', encoding='utf8') as f:
lines = f.readlines() # 列表
# print(type(lines), lines)
with open(f'result\\data_late.txt', "w", encoding='utf-8') as f:
for line in lines:
line = line.strip() # 去除\n
for string in strings:
if line in string:
print(f'【【{string}】】包含【【{line}】】,【【{string}】】已去除!')
f.write(f'{string}\n')
strings.remove(string)
标签:string,python,excel,lines,print,line,txt,strings
From: https://www.cnblogs.com/code3/p/17392434.html