word 添加水印

import win32com
from win32com.client import Dispatch
import os,time


def getWordAddWatermark(file_path, context):
"""

:param file_path: 文件的路徑
:param context: 水印的內容
:return:
"""
wordApp = win32com.client.DispatchEx("Word.Application") # 打開word進程
wordApp.Visible = True
# wordApp.DisplayAlerts = False
doc = wordApp.Documents.Open(file_path)

actDoc = wordApp.ActiveDocument
Sect = actDoc.Sections(1).Range.Select()
wordApp.ActiveWindow.ActivePane.View.SeekView = 9

wordApp.Selection.HeaderFooter.Shapes.AddTextEffect(0, context, "等線", 1, False, False, 0, 0).Select()

# wordApp.Selection.ShapeRange.Name = '0'
wordApp.Selection.ShapeRange.TextEffect.NormalizedHeight = False
wordApp.Selection.ShapeRange.Line.Visible = False
wordApp.Selection.ShapeRange.Fill.Visible = True
wordApp.Selection.ShapeRange.Fill.Solid

# wordApp.Selection.ShapeRange.Fill.Transparency = 0.5
# 設置顏色
wordApp.Selection.ShapeRange.Fill.ForeColor.ObjectThemeColor = 0

wordApp.Selection.ShapeRange.Rotation = 315
wordApp.Selection.ShapeRange.LockAspectRatio = True
wordApp.Selection.ShapeRange.Height = 120
wordApp.Selection.ShapeRange.Width = 320
wordApp.Selection.ShapeRange.WrapFormat.AllowOverlap = True

wordApp.Selection.ShapeRange.WrapFormat.Type = 3
wordApp.Selection.ShapeRange.WrapFormat.Side = 3
wordApp.Selection.ShapeRange.RelativeVerticalPosition = 0
wordApp.Selection.ShapeRange.Left = -999995
wordApp.Selection.ShapeRange.Top = -999995

# 關閉頁眉頁腳
wordApp.ActiveWindow.ActivePane.View.SeekView = 0
actDoc.Save()
actDoc.Close()

os.system("taskkill /f /im WINWORD.EXE")


if __name__ == '__main__':
getWordAddWatermark(r'C:\Users\Administrator\Desktop\需求\產品信息日報表需求\cc.docx', '光大理財')
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章