c#生成word水印

ContractedBlock.gif ExpandedBlockStart.gif Code
 1ExpandedBlockStart.gifContractedBlock.gif /**//// <summary>
 2InBlock.gif        /// 加水印函数
 3InBlock.gif        /// </summary>
 4InBlock.gif        /// <param name="docName">文件名 </param>
 5InBlock.gif        /// <param name="FilePath">文件路径</param>
 6ExpandedBlockEnd.gif        /// <param name="SavePath">保存路径</param>

 7None.gif        public void CreateWordFile(string docName,string FilePath,string SavePath)
 8ExpandedBlockStart.gifContractedBlock.gif        dot.gif{
 9InBlock.gif            System.Windows.Forms.Application.DoEvents(); 
10InBlock.gif            object Nothing = System.Reflection.Missing.Value;
11InBlock.gif            object filename = FilePath + "\\" + docName;
12InBlock.gif            object docname = SavePath + "\\" + docName;
13InBlock.gif            Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
14InBlock.gif            Microsoft.Office.Interop.Word.Document WordDoc = WordApp.Documents.Open(ref filename, ref Nothing, ref Nothing,
15InBlock.gif                ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing,
16InBlock.gif                ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
17InBlock.gif                try
18ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
19InBlock.gif                    WordDoc.Application.ActiveWindow.Selection.Range.Select();
20InBlock.gif                    WordDoc.Application.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
21InBlock.gif                    WordDoc.Application.Selection.HeaderFooter.Shapes.AddPicture(textBox3.Text.Trim(), ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing).Select(ref Nothing);
22InBlock.gif                    WordDoc.Application.Selection.ShapeRange.Name = "WordPictureWatermark1";
23InBlock.gif                   WordDoc.Application.Selection.ShapeRange.LockAspectRatio = MsoTriState.msoTrue;
24InBlock.gif                    WordDoc.Application.Selection.ShapeRange.Height = 845f;
25InBlock.gif                    WordDoc.Application.Selection.ShapeRange.Width = 595f;
26InBlock.gif                    WordDoc.Application.Selection.ShapeRange.Left = -999998f; //WdShapePosition.wdShapeCenter;居中
27InBlock.gif                    WordDoc.Application.Selection.ShapeRange.Top = -999999f;// WdShapePosition.wdShapeCenter;居中
28InBlock.gif                    WordDoc.Application.Selection.ShapeRange.WrapFormat.AllowOverlap = 0;
29InBlock.gif                    WordDoc.Application.Selection.ShapeRange.LayoutInCell =0;
30InBlock.gif                    WordDoc.Application.Selection.ShapeRange.WrapFormat.Side = WdWrapSideType.wdWrapBoth;
31InBlock.gif                    WordDoc.Application.Selection.ShapeRange.WrapFormat.Type = WdWrapType.wdWrapNone;                   // 
32InBlock.gif                    WordDoc.Application.Selection.ShapeRange.ZOrder(MsoZOrderCmd.msoSendBehindText);//文本底下
33InBlock.gif                    WordDoc.Application.Selection.ShapeRange.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
34InBlock.gif                    WordDoc.Application.Selection.ShapeRange.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
35InBlock.gif                    WordDoc.Application.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;
36InBlock.gif                    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);
37InBlock.gif                    WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
38InBlock.gif                    WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
39InBlock.gif               if (checkBox1.Checked)
40ExpandedSubBlockStart.gifContractedSubBlock.gif               dot.gif{
41InBlock.gif                   DeleteWord(filename.ToString());
42ExpandedSubBlockEnd.gif               }

43ExpandedSubBlockEnd.gif            }

44InBlock.gif            catch (Exception ee)
45ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
46InBlock.gif                WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
47InBlock.gif                WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
48InBlock.gif                MessageBox.Show(ee.ToString());
49ExpandedSubBlockEnd.gif            }

50InBlock.gif            finally
51ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
52InBlock.gif               // WordDoc1.Close(ref Nothing, ref Nothing, ref Nothing);
53InBlock.gif                //WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
54InBlock.gif                //WordApp.Quit(ref Nothing, ref Nothing, ref Nothing);  
55ExpandedSubBlockEnd.gif            }

56InBlock.gif            
57ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/qyfan82/archive/2008/03/17/1109298.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值