private void button1_Click(object sender, EventArgs e)
{
string test1 = "C:\\test.docx";//源文件
string test2 = "D:\\test.docx";//添加后的文件
AddWaterMark("test", test1, test2);//添加水印
} public void AddWaterMark(string docName, string FilePath, string SavePath)
{
System.Windows.Forms.Application.DoEvents();
object Nothing = System.Reflection.Missing.Value;
object filename = FilePath;
object docname = SavePath;
//图片存放位置
String logoPath = "D:\\1.jpg";
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref filename, 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);
try
{
WordDoc.Application.ActiveWindow.Selection.Range.Select();
WordDoc.Application.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
//增加水印图片
WordDoc.Application.Selection.HeaderFooter.Shapes.AddPicture(logoPath, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing).Select(ref Nothing);
//增加水印文字
WordDoc.Application.Selection.HeaderFooter.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, "Dog", "Arial", (float)100, MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 0, ref Nothing).Select(ref Nothing);
WordDoc.Application.Selection.ShapeRange.Name = "WordPictureWatermark1";
WordDoc.Application.Selection.ShapeRange.LockAspectRatio = MsoTriState.msoTrue;
WordDoc.Application.Selection.ShapeRange.Height = 845f;
WordDoc.Application.Selection.ShapeRange.Width = 595f;
WordDoc.Application.Selection.ShapeRange.Left = -999998f; //WdShapePosition.wdShapeCenter;居中
WordDoc.Application.Selection.ShapeRange.Top = -999999f;// WdShapePosition.wdShapeCenter;居中
WordDoc.Application.Selection.ShapeRange.WrapFormat.AllowOverlap = 0;
WordDoc.Application.Selection.ShapeRange.LayoutInCell = 0;
WordDoc.Application.Selection.ShapeRange.WrapFormat.Side = WdWrapSideType.wdWrapBoth;
WordDoc.Application.Selection.ShapeRange.WrapFormat.Type = WdWrapType.wdWrapNone; //
WordDoc.Application.Selection.ShapeRange.ZOrder(MsoZOrderCmd.msoSendBehindText);//文本底下
WordDoc.Application.Selection.ShapeRange.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
WordDoc.Application.Selection.ShapeRange.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
WordDoc.Application.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
WordDoc.SaveAs(ref docname, 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);
WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
}
catch (Exception ee)
{
}
finally
{
}
}
}

最新文章

  1. thinkphp自定义标签库
  2. I/O 请求数据包
  3. Oracle Linux
  4. android 点击屏幕关闭 软键盘
  5. 渐变背景 css3渐变效果及代码
  6. Solaris桌面CDE
  7. [转]javascript中style.left和offsetLeft的使用
  8. Linux中应用程序如何使用系统调用syscall
  9. java Double保留小数点位数
  10. PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings.
  11. Jdbc访问数据库篇
  12. 【扩展欧几里得】NOIP2012同余方程
  13. Python 练习——计算1-2+3-4...+99
  14. 使用Fiddle抓取IOS手机
  15. 定制FileField中的上传文件名称
  16. 深入理解Linux网络技术内幕——PCI层和网络接口卡
  17. C# 中 PadLeft和PadRight 的用法
  18. Android 权限信息
  19. 基于.Net下整合RestSharp,实现REST服务客户端
  20. ffpmeg下rtmp踩坑记录

热门文章

  1. HDU 5461:Largest Point
  2. vs2012(或2013)与虚拟机连调试
  3. 抗干扰性极强非接触式读卡13.56mhz芯片:SI522
  4. COGS1487 麻球繁衍
  5. 十四、CI框架之数据库以参数形式插入操作
  6. Resource interpreted as Stylesheet but transferred with MIME || DevTools failed to parse SourceMap:
  7. jobs|ps|杀死nohup
  8. Q6:ZigZag Conversion
  9. aliyun二级域名绑定
  10. LeetCode 543. Diameter of Binary Tree 二叉树的直径 (C++/Java)