如何给word添加水印呢,要哪种可以将水印铺满整个页面的,就跟在word文档中设置水印一样。各位大侠啊,求救啊,只要能实现有,分多多啊
解决方案 »
- asp.net 动态生成页面 性能
- 跨网站共享账号密码如何实现
- ASP.NET 的传值?CommandArgument CommandArgument 的运用
- 请问关于自动登陆
- 更新记录时如何才能不更新当天的记录?
- repeater内使用RadioButtonlist的问题
- 如何得到网站根目录
- 如何在宿主页面点按钮动态加载用户控件?
- 为何弹出“输入网络密码”对话框?
- [ 代码发布 ] asp.net服务器和客户端脚本即时通信。 Lostinet.Janc (附加聊天室做例子)
- 有没有通过强类型DataSet直接生成基础BLL的工具?
- Panel的style(overflow-Y)在VS2005里应该如何表示?
public void show()
{
object Nothing = System.Reflection.Missing.Value;
Word.ApplicationClass wordAppObj = null;
Word.Document WordDoc = null;
try
{
// object srcFileName = Server.MapPath("Documnets") + "/ProjectTmp.doc";
// object dstFileName = Server.MapPath("Documnets") + "/Project.doc";
string FileName = Server.MapPath("ImgWaterMark") + "/WaterMark_W_W.bmp";
object srcFileName = "C:\\aa.doc";
object dstFileName = "C:\\bb.doc";
object obj = true;
wordAppObj = new Word.ApplicationClass();
WordDoc = wordAppObj.Documents.Open(ref srcFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
this.CreateWaterMarkImg("与电子文本一致", WordDoc.ActiveWindow.Height, WordDoc.ActiveWindow.Width, WordDoc.ActiveWindow.Width, WordDoc.ActiveWindow.Height);
this.CreateWaterMarkImgT("", WordDoc.ActiveWindow.Height, WordDoc.ActiveWindow.Width, WordDoc.ActiveWindow.Width, WordDoc.ActiveWindow.Height);
Word.Shape oShape;
WordDoc.ActiveWindow.View.Type = Word.WdViewType.wdOutlineView;
WordDoc.ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekPrimaryHeader;
// WordDoc.ActiveWindow.ActivePane.Selection.InsertAfter(DateTime.Now.ToString("yyyyMMddhhssmm"));
object top = 36;
oShape = WordDoc.ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddPicture(FileName, ref Nothing,
ref Nothing, ref Nothing, ref top, ref Nothing, ref Nothing, ref Nothing);
oShape.WrapFormat.Type = Word.WdWrapType.wdWrapInline;
oShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
WordDoc.SaveAs(ref dstFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); }
catch (Exception ex)
{ }
finally
{
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordAppObj.Quit(ref Nothing, ref Nothing, ref Nothing);
}
}
参考地址:http://www.cnblogs.com/tianshikuqi8/archive/2009/04/13/1434687.html
试了下可以添加 但是没有平铺
protected void Button1_Click1(object sender, EventArgs e)
{
WaterMarkToWord("C:\\1.jpg", "c:\\cccc.doc", "c:\\cccc.doc");
}
public void WaterMarkToWord(string imgName, object srcFileName, object dstFileName)
{
object Nothing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.ApplicationClass wordAppObj = null;
Microsoft.Office.Interop.Word.Document wordDoc = null;
try
{
object obj = true;
wordAppObj = new Microsoft.Office.Interop.Word.ApplicationClass();
wordDoc = wordAppObj.Documents.Open(ref srcFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
Microsoft.Office.Interop.Word.Shape oShape;
wordDoc.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;
wordDoc.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;
//WordDoc.ActiveWindow.ActivePane.Selection.InsertAfter(DateTime.Now.ToString("yyyyMMddhhssmm"));
object left = wordDoc.ActiveWindow.Width / 4;
object top = wordDoc.ActiveWindow.Height / 2; oShape = wordDoc.ActiveWindow.ActivePane.Selection.HeaderFooter.Shapes.AddPicture(imgName, ref Nothing,
ref Nothing, ref left, ref top, ref Nothing, ref Nothing, ref Nothing);
oShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapInline;
oShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBehindText);
wordDoc.SaveAs(ref dstFileName, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
}
catch (Exception ex)
{
}
finally
{
wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
wordAppObj.Quit(ref Nothing, ref Nothing, ref Nothing);
}
}