Dim rt As prt.RenderText '定义一个文本对象
Dim tm As String = ProjectPath & "Attachments\工程内部协议基本情况表.docx" '指定模板文件
Dim fl As String = ProjectPath & "Reports\工程内部协议基本情况表.docx" '指定目标文件
'设置水印
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(tm)
With doc
.Activate
app.WordBasic.RemoveWatermark '删除旧的水印
For Each oSec As object In doc.Sections '文档的节中循环
Dim myRange = oSec.Headers(MSWord.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
myRange.Delete '删除页眉中的内容
Next
.Sections(1).Range.Select
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader '插入水印前需更改视图样式为页眉视图
Dim i As Integer
Dim nr As String = Tables("内部合同").Current("项目名称") & vbcrlf & Date.Now
For i = 1 To 1 '水印数量
'设置插入水印,语法:表达式.AddTextEffect(预设文字效果, 文字内容, 字体名, 字体大小, 是否粗体, 是否斜体, 左侧位置, 顶部位置)
app.Selection.HeaderFooter.Shapes.AddTextEffect(10, nr,"宋体", 25, False, False, 100,i*200).Select '水印如何居中
Next
app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument '恢复视图样式到原来样式
End With
doc.save
app.quit
catch ex As exception
app.quit
End try
'打开报表
Dim wrt As New WordReport(Tables("内部合同"),tm,fl) '定义一个WordReport
wrt.Build() '逐行生成报表
wrt.Show() '显示报表
老师帮忙看看新问题
1.页眉中加内容 =Tables("内部合同").Current("项目名称")
2.水印如何上下左右居中
是不是用 app.AlignHorzEnum.Center
[此贴子已经被作者于2019/2/23 10:48:32编辑过]