[D]python扩展pywin32添加word文字水印

hit_liuanhuaming 2012-07-10 02:49:55
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
...全文
516 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hit_liuanhuaming 2012-07-11
  • 打赏
  • 举报
回复
搞定了,office版本问题
hit_liuanhuaming 2012-07-10
  • 打赏
  • 举报
回复
这个可行。问题可能是python的扩展pywin32有bug。谢谢了,请问VB怎么写呀
bugs2k 2012-07-10
  • 打赏
  • 举报
回复
w = win32com.client.Dispatch('Word.Application')


没做过操作 word 的,这个可行不?
貌似一般都用 VB / C# / VC 来做啊?

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧