1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. string test1 = "C:\\test.docx";//源文件
  4. string test2 = "D:\\test.docx";//添加后的文件
  5. AddWaterMark("test", test1, test2);//添加水印
  6. }
  7.  
  8. public void AddWaterMark(string docName, string FilePath, string SavePath)
  9. {
  10. System.Windows.Forms.Application.DoEvents();
  11. object Nothing = System.Reflection.Missing.Value;
  12. object filename = FilePath;
  13. object docname = SavePath;
  14. //图片存放位置
  15. String logoPath = "D:\\1.jpg";
  16. Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
  17. Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref filename, ref Nothing, ref Nothing,
  18. ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
  19. ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
  20. try
  21. {
  22. WordDoc.Application.ActiveWindow.Selection.Range.Select();
  23. WordDoc.Application.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
  24. //增加水印图片
  25. WordDoc.Application.Selection.HeaderFooter.Shapes.AddPicture(logoPath, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing).Select(ref Nothing);
  26. //增加水印文字
  27. WordDoc.Application.Selection.HeaderFooter.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, "Dog", "Arial", (float)100, MsoTriState.msoTrue, MsoTriState.msoFalse, 0, 0, ref Nothing).Select(ref Nothing);
  28. WordDoc.Application.Selection.ShapeRange.Name = "WordPictureWatermark1";
  29. WordDoc.Application.Selection.ShapeRange.LockAspectRatio = MsoTriState.msoTrue;
  30. WordDoc.Application.Selection.ShapeRange.Height = 845f;
  31. WordDoc.Application.Selection.ShapeRange.Width = 595f;
  32. WordDoc.Application.Selection.ShapeRange.Left = -999998f; //WdShapePosition.wdShapeCenter;居中
  33. WordDoc.Application.Selection.ShapeRange.Top = -999999f;// WdShapePosition.wdShapeCenter;居中
  34. WordDoc.Application.Selection.ShapeRange.WrapFormat.AllowOverlap = 0;
  35. WordDoc.Application.Selection.ShapeRange.LayoutInCell = 0;
  36. WordDoc.Application.Selection.ShapeRange.WrapFormat.Side = WdWrapSideType.wdWrapBoth;
  37. WordDoc.Application.Selection.ShapeRange.WrapFormat.Type = WdWrapType.wdWrapNone; //
  38. WordDoc.Application.Selection.ShapeRange.ZOrder(MsoZOrderCmd.msoSendBehindText);//文本底下
  39. WordDoc.Application.Selection.ShapeRange.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
  40. WordDoc.Application.Selection.ShapeRange.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
  41. WordDoc.Application.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
  42. 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);
  43. WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
  44. WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
  45. }
  46. catch (Exception ee)
  47. {
  48. }
  49. finally
  50. {
  51. }
  52. }
  53. }

给Office文档添加水印效果【测试有效】的更多相关文章

  1. 在线预览-Java 使用 Print2Flash 实现Office文档在线阅读

    近期项目上遇到一个需求是用户上传的文档进行在线浏览,之前有过一篇使用 OpenOffice 将 word 转换成 html 页面进行展示的.现在介绍一个新的工具那就是 Print2Flash .    ...

  2. java将office文档pdf文档转换成swf文件在线预览

    第一步,安装openoffice.org openoffice.org是一套sun的开源office办公套件,能在widows,linux,solaris等操作系统上执行. 主要模块有writer(文 ...

  3. OFFICE 文档转换为html在线预览

    OFFICE 文档在线预览方案很多: 服务器先转换为PDF,再转换为SWF,最后通过网页加载Flash预览,比如flexpaper Office文档直接转换为SWF,通过网页加载Flash预览 微软的 ...

  4. JAVA实现在线查看PDF和office文档

    一个项目中要做一个在线预览附件(和百度文库差不多)的小功能点,楼主在开发过程中踩了很多坑的同时也总结了一些方法,仅供广大猿友参考,那么要实现这个小功能,目前主要是有如下3种可行的实现方式,下面先说实现 ...

  5. 使用WebDAV实现Office文档在线编辑

    Office的文档处理能力是非常强大的,但是它是本地资源,在Office Web App尚未成熟前,仍需要使用本地能力来进行文档编辑,可是现代的系统的主流却是B/S,所以在B/S中调用本地的Offic ...

  6. Java实现web在线预览office文档与pdf文档实例

    https://yq.aliyun.com/ziliao/1768?spm=5176.8246799.blogcont.24.1PxYoX 摘要: 本文讲的是Java实现web在线预览office文档 ...

  7. Java版office文档在线预览

    java将office文档pdf文档转换成swf文件在线预览 第一步,安装openoffice.org openoffice.org是一套sun的开源office办公套件,能在widows,linux ...

  8. 在禅道中实现WORD等OFFICE文档转换为PDF进行在线浏览

    条件: 安装好禅道的服务器 能直接浏览PDF的浏览器(或通过 安装插件实现 ) 文档转换服务程序(建议部署在另一台服务器上)     实现 原理: 修改禅道的文件预览功能(OFFICE文档其使用的是下 ...

  9. Java实现office文档与pdf文档的在线预览功能

    最近项目有个需求要java实现office文档与pdf文档的在线预览功能,刚刚接到的时候就觉得有点难,以自己的水平难以在三四天做完.压力略大.后面查找百度资料.以及在同事与网友的帮助下,四天多把它做完 ...

随机推荐

  1. Kali链接Xshell和更新源

    一.Xshell首次链接kali系统中的ssh Xshell:帮助我们去连接各种服务平台,方便管理服务器,链路可以加密处理(ssh/vsftp) 1.开启kali中的ssh服务,service ssh ...

  2. 51nod 1475:建设国家 优先队列的好题

    1475 建设国家 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题  收藏  关注 小C现在想建设一个国家.这个国家中有一个首都,然后有若干个中间站,还有若干个城市 ...

  3. 1 - apicloud - str 字符串拼接技术

    <body> <label>Hello APP</label> <div id='sys-info'></div></body> ...

  4. BZOJ 5059 前鬼后鬼的守护

    题解: 解法一:用函数斜率什么的,不会,留坑 解法二: 某一个序列都变成一个值那么中位数最优 加入一个元素,与前面那一段区间的中位数比较 x>=mid什么事也不做 x<mid合并两端区间 ...

  5. ABP框架没有httpPost,httpget,httpput特性

    需要引用一下组件, Microsoft.AspNetCore.Mvc

  6. Python模拟登录哔哩哔哩

    嘿,各位小伙伴中午好呀,今天要带来点什么干货呢,就从我的实际开发中来给大家带来一个案例吧,如何自动登录哔哩哔哩. ! 接到老大通知,让我自动写一个自动登录哔哩哔哩的脚本,我当然是二话不说直接开怼,咱们 ...

  7. 十七、CI框架之数据库操作insert用法

    一.代码如下: 二.我们访问一下页面 三.查看数据库,已经插入了一条数据 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.

  8. idea自定义模版

    点小灯 编辑live模版设置 模版全称 private static final Logger logger = LoggerFactory.getLogger($classname$.class); ...

  9. 吴裕雄--天生自然C++语言学习笔记:C++ 变量类型

    变量其实只不过是程序可操作的存储区的名称.C++ 中每个变量都有指定的类型,类型决定了变量存储的大小和布局,该范围内的值都可以存储在内存中,运算符可应用于变量上. 变量的名称可以由字母.数字和下划线字 ...

  10. 关于SOA的架构设计案例分析

    SOA体系架构及相关技术,主要应用在企业应用集成领域,它能够以服务的方式共享和复用企业现有应用资产,保护用户IT投资,并能够以服务的方式构建新的业务流程,对企业流程进行灵活重构和优化,增强业务的敏捷性 ...