MH H
@brightur9701
Reviews Written
6
Average Rating
5.0
Posts
Q&A
๋ฐ์ค์ณ์ง ๋จ์ด๋ฅผ ๊ดํธ๋ก ๊ฐ์ธ๋ ๋ฐฉ๋ฒ์ด ์์๊น์?
while๋ฌธ์ ์ด๋ ๊ฒ ์์ ํ๋๋ ํด๊ฒฐ ๋์์ต๋๋ค^^๊ฐ์ฌํฉ๋๋ค~ while hwp.HAction.Execute("RepeatFind", pset.HSet): underline_wordlist.append(hwp.get_selected_pos()) pset.IgnoreMessage = 1 # Do not display pop-up return underline_wordlist
- 1
- 5
- 1K
Q&A
๋ฐ์ค์ณ์ง ๋จ์ด๋ฅผ ๊ดํธ๋ก ๊ฐ์ธ๋ ๋ฐฉ๋ฒ์ด ์์๊น์?
๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ์ ์ฅํ๋ ๊ฒ์ ์ฝ๋๋ฅผ ์์ ํด์ ์ฑ๊ณตํ์ต๋๋ค. import os from pyhwpx import Hwp def process_hwp_files(folder_path): # Check if the folder exists if not os.path.exists(folder_path): print(f"Folder does not exist: {folder_path}") return # Iterate through files in the folder for filename in os.listdir(folder_path): file_path = os.path.join(folder_path, filename) # Check if it's a file with the specified extensions if os.path.isfile(file_path) and (filename.lower().endswith('.hwp') or filename.lower().endswith('.hwpx')): process_single_hwp_file(file_path) def process_single_hwp_file(file_path): try: hwp = Hwp() hwp.open(file_path) underline_wordlist = find_underlined_words(hwp) pset = hwp.HParameterSet.HFindReplace pset.IgnoreMessage = 1 # Do not display pop-up for selected_range in underline_wordlist: hwp.select_text(selected_range) hwp.set_font(UnderlineType=0) # Remove underline hwp.Cut() hwp.insert_text("( ") hwp.Paste() hwp.insert_text(" )") save_path = add_suffix_to_filename(file_path, "Modified") hwp.save_as(save_path) hwp.close() except Exception as e: print(f"Error processing file '{file_path}': {e}") def find_underlined_words(hwp): pset = hwp.HParameterSet.HFindReplace # hwp.HAction.GetDefault("RepeatFind", pset.HSet) pset.FindCharShape.UnderlineType = 1 # Find underline pset.IgnoreFindString = 1 # Ignore what to find pset.Direction = 1 # Reverse order pset.IgnoreMessage = 1 # Do not display pop-up underline_wordlist = [] hwp.MoveDocEnd() while hwp.HAction.Execute("RepeatFind", pset.HSet): underline_wordlist.append(hwp.get_selected_pos()) return underline_wordlist def add_suffix_to_filename(file_path, suffix): base_path, ext = os.path.splitext(file_path) modified_path = f"{base_path}_{suffix}{ext}" return modified_path # Example Usage folder_to_process = r"E:\codingData\2023exam" process_hwp_files(folder_to_process)
- 1
- 5
- 1K
Q&A
๋ฐ์ค์ณ์ง ๋จ์ด๋ฅผ ๊ดํธ๋ก ๊ฐ์ธ๋ ๋ฐฉ๋ฒ์ด ์์๊น์?
์ค๊ฐ์ ํ์ ์ฐฝ์ด ๋จ๋ ๊ฒ ๋นผ๊ณค ๋ค ์ ์๋ํฉ๋๋ค. ChatGPT๋ฅผ ํ์ฉํ์ฌ ์์ฑํ ์ฝ๋๋ฅผ ์ฌ๋ ค๋ด ๋๋ค. ํ๋ฒ ์ ๊ฒ๋ถํ๋๋ฆฝ๋๋ค. ํน์ ํด๋ ๋ด์ ํ์ผ๋ค์ ๋ฐ์ค๋จ์ด๋ฅผ ๊ดํธ๋ก ๋ฐ๊พผํ์ ๋ง์ง๋ง์ ๋ค๋ฅธ์ด๋ฆ์ผ๋ก ์ ์ฅํ๋ ค๊ณ ํ๋๋ฐ ๊ทธ๊ฒ์ ์ฑ๊ณตํ์ง ๋ชปํ์ต๋๋ค.
- 1
- 5
- 1K




