python으로 엑셀 파일에서 특정 텍스트를 찾아서 바꾸고 저장하기.
예제.
import openpyxl
from openpyxl.utils.cell import get_column_letter
wb = openpyxl.load_workbook('22bj.xlsx')
sheet=wb['seoul22']
number_rows = sheet.max_row
number_columns = sheet.max_column
replacement = {'엔사운드(NSound) 목걸이형': '엔사운드 목걸이형', '언어,인지,수리력 향상프로그램세트': '언어,인지,수리력 향상프로그램 세트'}
for i in range(number_columns):
for k in range(number_rows):
cell = str(sheet[get_column_letter(i+1)+str(k+1)].value)
for key in replacement.keys():
if str(cell) == key:
newCell = replacement.get(key)
sheet[get_column_letter(i+1)+str(k+1)] = str(newCell)
wb.save('22bj1.xlsx')
wb = openpyxl.load_workbook('22bj.xlsx')
sheet=wb['seoul22']
number_rows = sheet.max_row
number_columns = sheet.max_column
replacement = {'엔사운드(NSound) 목걸이형': '엔사운드 목걸이형', '언어,인지,수리력 향상프로그램세트': '언어,인지,수리력 향상프로그램 세트'}
for i in range(number_columns):
for k in range(number_rows):
cell = str(sheet[get_column_letter(i+1)+str(k+1)].value)
for key in replacement.keys():
if str(cell) == key:
newCell = replacement.get(key)
sheet[get_column_letter(i+1)+str(k+1)] = str(newCell)
wb.save('22bj1.xlsx')
댓글 없음:
댓글 쓰기