import os
import tkinter as tk
from tkinter.filedialog import askopenfilename
import win32com.client as win32
def 엑셀실행(filepath):
excel = win32.gencache.EnsureDispatch("Excel.Application")
excel.Visible = True
wb = excel.Workbooks.Open(filepath)
ws = wb.Worksheets(1)
return excel, wb, ws
def 사전형변환(data):
data = {i: j for (i, j) in data[1:]}
return data
def 엑셀종료():
excel.Quit()
def 한글실행(filepath):
hwp = win32.gencache.EnsureDispatch("hwpframe.hwpobject")
hwp.RegisterModule("FilePathCheckDLL", "FilePathCheckerModule")
hwp.Open(filepath, arg="versionwarning:False")
hwp.XHwpWindows.Item(0).Visible = True
return hwp
def 자동교정(target):
hwp.HAction.GetDefault("AllReplace", hwp.HParameterSet.HFindReplace.HSet)
hwp.HParameterSet.HFindReplace.Direction = hwp.FindDir("AllDoc")
hwp.HParameterSet.HFindReplace.FindString = target
hwp.HParameterSet.HFindReplace.ReplaceString = 엑셀데이터[target]
hwp.HParameterSet.HFindReplace.ReplaceMode = 1
hwp.HParameterSet.HFindReplace.IgnoreMessage = 1
hwp.HParameterSet.HFindReplace.FindType = 1
hwp.HAction.Execute("AllReplace", hwp.HParameterSet.HFindReplace.HSet)
def 일괄교정(data):
for i in data.keys():
자동교정(i)
if __name__ == '__main__':
root = tk.Tk() # GUI 실행하고
root.withdraw() # GUI 콘솔창 안나타나게
엑셀파일_경로 = askopenfilename(title="교정표 엑셀 파일을 선택해주세요.",
initialdir=os.getcwd(),
filetypes=[("엑셀파일", "*.xls *.xlsx *.hcell")])
한글파일_경로 = askopenfilename(title="교정한 한/글 파일을 선택해주세요.",
initialdir=os.getcwd(),
filetypes=[("아래아한글파일", "*.hwp *.hwpx")])
root.destroy() # GUI 종료
excel, wb, ws = 엑셀실행(엑셀파일_경로)
엑셀데이터 = 사전형변환(ws.UsedRange())
엑셀종료()
hwp = 한글실행(한글파일_경로)
일괄교정(엑셀데이터)