2025.03.01 - [파이썬 업무 자동화/한글 문서 작업 자동화] - 파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 7. 현재 폴더 위치 적용
파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 7. 현재 폴더 위치 적용
2025.03.01 - [파이썬 업무 자동화/한글 문서 작업 자동화] - 파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 6. 실행 파일 변환 파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 6. 실행 파일 변환202
sunnysides.tistory.com
양식 파일은 내용이 바뀌어도 그냥 새로 저장하면 되는데, 피디에프 파일 제목은 (공문명)-(회사명).pdf 이렇게 저장되면 좋겠죠?
프로그램에서 알아서 회사명으로 저장은 해주는데, 앞에 공문명은 내가 임의로 입력하면 좋겠네요!
입력값 받아오기
파이썬에서 입력은 input이라는 함수로 받아올 수 있답니다.
간단하게
x = input('값을 입력하고 엔터를 눌러주세요 :')
이렇게 함수 안에 값이 화면에 나오게 되고, 이후에 받은 입력 값을 x에 저장한답니다.
그럼 이전 코드에 해당 코드를 추가하도록 바꿔 보겠습니다.
def getFiles():
import os
current_dir = os.path.dirname(__file__)
file_list = os.listdir(current_dir)
for file in file_list:
if '.xlsx' in file:
xl_file = file
elif '.hwp' in file:
hwp_file = file
pdf_file = file.replace('.hwp','.pdf')
if 'output' not in file_list:
os.mkdir(current_dir +'/output')
pdf_path = current_dir +'/output/'
return current_dir+'/', xl_file, hwp_file, pdf_file, pdf_path
def getCompanyNames(xl_path,xl_file):
from openpyxl import load_workbook
file_path = xl_path + xl_file
wb = load_workbook(file_path)
ws = wb.active
total_rows = sum(1 for row in ws["B"] if row.value is not None)
company_list = []
for i in range(total_rows-1):
company_list += [ws['B%s'%(i+2)].value]
return company_list
def getPDFfromBodyChange(hwp_path,hwp_file,pdf_path,company_name,event):
import win32com.client as win32
hwp = win32.Dispatch("HWPFrame.HwpObject")
hwp.XHwpWindows.Item(0).Visible = True
file_path = hwp_path+hwp_file
pdf_path1 = pdf_path+'%s-%s.pdf'%(event,company_name)
hwp.Open(file_path,'HWP','forceopen:true')
hwp.PutFieldText("field",r' 까꿍')
hwp.SetMessageBoxMode(0x1000)
hwp.SaveAs(pdf_path+'%s.hwp'%(company_name),'HWP','')
action = hwp.CreateAction("Print")
option = action.CreateSet()
action.GetDefault(option)
option.SetItem("Device", 3)
option.SetItem("FileName", pdf_path1)
action.Execute(option)
hwp.Quit()
return
current_folder,xl,hwp,pdf,pdf_folder = getFiles()
company_list = getCompanyNames(current_folder,xl)
event = input(r'공문명을 입력하고 엔터를 누르세요: ')
for company in company_list:
getPDFfromBodyChange(current_folder,hwp,pdf_folder,company,event)
해당 코드를 실행하면
이렇게 입력값을 받을 수 있고,
이렇게 pdf 앞에 aa-라는 문구가 추가되게 된답니다!
event라는 변수가 중간중간 추가된 것 말고 바뀐 부분은 없습니다. 지금까지와 다르게 엄청나게 간단한 내용이었네요. 다행입니다...ㅋㅋㅋㅋㅋ 좀 허무한 것 같기도 하고...
다음 시간엔 이렇게 만든 코드를 실행파일로 바꿔서 주변 사람에게 공유할 수 있도록 변환해보도록 하겠습니다.
'코딩 프로젝트 > 파이썬-한글 매크로 프로그램 제작' 카테고리의 다른 글
파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 9. 한글 공문 매크로 프로그램 (프로그램 첨부) (0) | 2025.03.02 |
---|---|
파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 7. 현재 폴더 위치 적용 (2) | 2025.03.01 |
파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 6. 실행 파일 변환 (0) | 2025.03.01 |
파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 5. 코드 합치기 (0) | 2025.03.01 |
파이썬 한글 매크로 프로그램 제작 (feat. ChatGPT) - 4. 한글 문서 pdf로 추출하기 (0) | 2025.02.25 |