[D]python扩展pywin32添加word文字水印
filenamein = 'E:\\honeypot\\wan.docx'
import win32com
from win32com.client import Dispatch, constants ,gencache
w = win32com.client.Dispatch('Word.Application')
# 后台运行,不显示,不警告
w.Visible = 0
w.DisplayAlerts = 0
# 打开新的文件
doc = w.Documents.Open(filenamein)
w.ActiveDocument.Sections(1).Range.Select
w.ActiveWindow.ActivePane.View.SeekView = 9
w.Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1,'保密','宋体',1,False,False,0,0).Select
w.Selection.ShapeRange.Name = 'PowerPlusWaterMarkObject1'
w.Selection.ShapeRange.TextEffect.NormalizedHeight = False
w.Selection.ShapeRange.Line.Visible = False
w.Selection.ShapeRange.Fill.Visible = True
w.Selection.ShapeRange.Fill.Solid
w.Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)
w.Selection.ShapeRange.Fill.Transparency = 0.5
w.Selection.ShapeRange.Rotation = 315
w.Selection.ShapeRange.LockAspectRatio = True
w.Selection.ShapeRange.Height = w.CentimetersToPoints(6.88)
w.Selection.ShapeRange.Width = w.CentimetersToPoints(13.77)
w.Selection.ShapeRange.WrapFormat.AllowOverlap = True
w.Selection.ShapeRange.WrapFormat.Side = 3
w.Selection.ShapeRange.WrapFormat.Type = 3
w.Selection.ShapeRange.RelativeVerticalPosition = 0
w.Selection.ShapeRange.Left = -999995
w.Selection.ShapeRange.Top = -999995
w.ActiveWindow.ActivePane.View.SeekView = 0
doc.Close()
w.Documents.Close(wc.wdDoNotSaveChanges)
w.Quit()
报错:NameError: name 'PowerPlusWaterMarkObject1' is not defined
office版本为2007 企业英文版,中文版也不行。这是什么原因?
---------------------------
Double行动:
原帖分数:40
帖子加分:40