don't stop believing

엑셀에 내가 찾는 문자가 있는지(없는지) 검색 본문

Python/openpyxl

엑셀에 내가 찾는 문자가 있는지(없는지) 검색

Tongchun 2017. 10. 20. 10:04

영어 단어 엑셀에서 Accent를 ^로 표현했다.

처음 단어 정리할때는 Accent표시를 안해서 Accent(^)표시가 없는게 있다.


Cell에서 Accent(^) 표시가 없는걸 찾고싶다.

우선 발음은 대괄호([ ])안에 표시되고 그 안에 Accent(^)가 없는걸 찾으면 된다.


먼저 String에 대한 검색은 아래와 같이 in으로 하면 된다.

1
2
>> 'Py' in 'Python'
True
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

이걸로 함수를 두개 만들어 준다.

findExistString(), findNonExistString()


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
# -*- coding:utf-8 -*-
import openpyxl
#
filename = "1-words.xlsm"
book = openpyxl.load_workbook(filename)
#
sheet = book.worksheets[0]
# True return .
def findExistString(searchString, text):
if searchString in text: return True
else: return False
# True return .
def findNonExistString(searchString, text):
if searchString in text: return False
else: return True
# .
for row in sheet.rows:
if findExistString("[", row[1].value):
if findNonExistString("^", row[1].value):
print(row[0].value)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


[https://docs.python.org/3/library/stdtypes.html]

[https://openpyxl.readthedocs.io/en/default/index.html]


Comments