300x250

Python 6

python office automation으로 열려진 워드의 문서 민감도 레이블 설정 (set sensitivity label)

열려진 워드에 접근하기 위해서 win32com을 import해서 사용 from win32com.client import Dispatch def set_sensitivitylabel(): word = win32.gencache.EnsureDispatch('Word.Application') word.Visible = True doc = word.Documents # 이미 열린 문서가 없음 if doc.Count == 0: return for docs in word.Documents: # label 생성 new_label = docs.SensitivityLabel.CreateLabelInfo() new_label.LabelName = '' new_label.LabelId = 'xxxxxxxx-xxxx-xxxx..

Python 2023.05.02

AttributeError: module 'win32com.gen_py.' has no attribute 'CLSIDToClassMap'

Office Automation 관련 개발 중 주말 지나고 와서 빌드를 하니 갑자기 처음보는 에러 메시지가 발생 문제가 발생하는 위치는 아래 코드에서 나타남 win32.gencache.EnsureDispatch('Word.Application') AttributeError: module 'win32com.gen_py.' has no attribute 'CLSIDToClassMap' stackoverflow 찾은 내용으로는 COM 관련 동적 바인딩에서 정적 바인딩을 변경 때문인 것으로 C:\사용자\AppData\Local\Temp\gen_py 폴더를 삭제 후 pycharm 등 다시 실행 후 python script를 실행하면 정상 동작하는 것을 확인할 수 있음 또는 win32.com.client.dynam..

Python 2023.05.02

python을 사용해서 Office에서 이미지 추출

python을 사용해서 Office 문서에서 이미지를 추출하는 코드를 작성해보겠습니다. docx/pptx/xlsx를 기준으로 작성을 진행하며, doc/ppt/xls 파일은 이전 작성 글을 참조해서 변환하는 코드를 추가해서 작성하시면 됩니다. https://incorea.tistory.com/152 import zipfile import docx2txt def unzip_xfile(file_path, save_path): with zipfile.ZipFile(file_path, 'r') as zip_ref: zip_ref.extractall(save_path) def extract_images_from_pptx(file_path, save_path): unzip_xfile(file_path, save_pa..

Python 2023.04.06

Python zip 함수

alpha = ['a', 'b', 'c'] digit = [1, 2, 3] alpha와 digit을 입력으로 a 1 b 2 c 3 과 같은 결과를 얻고 싶은 경우 alpha = ['a', 'b', 'c'] digit = [1, 2, 3] for s1, s2 in alpha, digit: print(s1, s2) 결과: ValueError: too many values to unpack (expected 2) 에러 발생 alpha와 digit의 element 개수가 3개인데 입력을 받는 s1, s2가 두 개이므로 에러 발생 alpha = ['a', 'b', 'c'] digit = [1, 2, 3] for s1, s2, s3 in alpha, digit: print(s1, s2, s3) 결과: a b c 1..

Python 2019.07.17
300x250