Skip to content

Instantly share code, notes, and snippets.

@JedBeom
Created August 9, 2021 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JedBeom/eeadd3458ea1ff7001edd9c8b374f265 to your computer and use it in GitHub Desktop.
Save JedBeom/eeadd3458ea1ff7001edd9c8b374f265 to your computer and use it in GitHub Desktop.
'''
파이썬을 이용해 한글 hwp 문서의 표를 읽는다.
공식 API를 이용하지 않고, 미리보기 글자를 읽는 식의 일종의 편법(?)을 이용한다.
Body 필드도 있던데, 지금 당장 필요치 않아서 사용하지 않는다.
참고: https://yahohococo.tistory.com/45
사용하는 대상 파일은 링크가 너무 길어서 아래 댓글에 남겨둔다.
'''
import olefile
f = olefile.OleFileIO("2021학년도 1학기 기말고사 시간표.hwp")
# 미리보기 텍스트를 읽은 후, UTF-16으로 디코드한 다음, 개행 문자를 교체한다.
text = f.openstream('PrvText').read().decode("UTF-16").replace("\r\n", "\n")
# 내용에 표는, 각 블럭이 <내용> 이런식으로 괄호로 감싸져 있어서, 괄호를... 좀 무식하게 제거한다.
texts = [x[:len(x)-1] for x in text.split("<")]
print(texts)
@JedBeom
Copy link
Author

JedBeom commented Aug 9, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment