Python

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

민토즈 2023. 5. 2. 14:21
300x250

열려진 워드에 접근하기 위해서 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-xxxx-xxxxxxxxxxxx' 
        docs.SensitivityLabel.SetLable(new_label, new_label)
    return

label 생성 시 label id는 compliance portal에서 생성한 민감도 레이블로부터 찾거나 powershell을 사용해서 직접 조회 

오피스 사용 시 로컬에 설치된 policy.xml로부터 참조 가능 

 

https://techcommunity.microsoft.com/t5/security-compliance-and-identity/how-to-troubleshoot-sensitivity-labels-part-1/ba-p/3604557

 

How to troubleshoot sensitivity Labels – Part 1

Often people came and asked this same question. Although all my eventual on-hands experience would increase, it can be tricky to answer to this question, or even just to give a straightforward method. To understand any kind of steps in a troubleshooting pr

techcommunity.microsoft.com

 

민감도 레이블 관련 powershell을 사용하는 방법에 대한 내용이 잘 정리되어 있습니다. 

 

300x250