해결된 질문
작성
·
163
·
수정됨
2
이건 질문 아닙니다. ^^
구현하고 싶은 간단한 내용이 있었는데,
강의에서 배운 내용을 기반으로 하고, A.I.에 질문하여 코드를 작성한 후 정상 작동에 성공했습니다.
저 같은 왕초보도 작동하는 뭔가를 만들어 내게 하는 이 강의는 정말 훌륭합니다~!
아주 기초적이고 작은 성공이라도 동기부여를 위해 소중합니다. ^^
# ■ 아래 코드의 용도 --- 작동 성공했음 _24-10-30 11:26
# "C:\\Users\\user\\Desktop\\제목 추가\\"에 여러 개의 hwp 파일들이 있을 때
# 파일을 하나씩 열고, 문서의 맨 처음으로 이동하여 파일명(~~~.hwp)을 타이핑하고 엔터를 3번 친 후 저장하고 닫기
import win32com.client as win32
hwp = win32.gencache.EnsureDispatch("hwpframe.hwpobject")
hwp.XHwpWindows.Item(0).Visible = True
hwp.RegisterModule("FilePathCheckDLL","FilePathCheckerModule")
import os
from time import sleep
os.chdir("C:\\Users\\user\\Desktop\\제목 추가\\") # r"C:\Users\user\Desktop\\제목 추가\\"로도 작동 성공함
for i in os.listdir():
hwp.Open(os.path.join(os.getcwd(), i))
sleep(0.2)
# 문서 객체 가져오기 --- 일코
doc = hwp.XHwpDocuments.Item(0)
# 전체 경로에서 파일명 추출 --- 일코, GPT
full_path = doc.FullName
file_name = os.path.basename(full_path)
# 커서를 원하는 위치로 이동 (예: 문서 맨 처음) --- GPT
hwp.HAction.Run("MoveTopLevelBegin")
# 파일명 입력 (타이핑) --- GPT
hwp.HAction.GetDefault("InsertText", hwp.HParameterSet.HInsertText.HSet)
hwp.HParameterSet.HInsertText.Text = file_name
hwp.HAction.Execute("InsertText", hwp.HParameterSet.HInsertText.HSet)
# 엔터를 3번 치기 --- GPT
for _ in range(3):
hwp.HAction.Run("BreakPara")
hwp.Save()
hwp.Clear(1)
답변