zoukankan      html  css  js  c++  java
  • 导出的Word中添加水印

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Core;
    
    namespace sciencePraiseSystem.BLL
    {
        public class ExportHelper
        {
            /// <summary>
            /// 
            /// </summary>
            /// <param name="doc"></param>
            /// <param name="text">水印文字</param>
            /// <param name="left">左间距</param>
            /// <param name="top">上间距</param>
            /// <param name="rotation"></param>
            /// <param name="height"></param>
            /// <param name="width"></param>
            /// <param name="size">文字大小</param>
            /// <param name="transparency">透明度</param>
            public static void AddWatermark(Microsoft.Office.Interop.Word.Document doc, string text, Microsoft.Office.Interop.Word.WdShapePosition left,
                Microsoft.Office.Interop.Word.WdShapePosition top, float rotation, float height, float width, float size, float transparency,
                Microsoft.Office.Interop.Word.WdColor color= Microsoft.Office.Interop.Word.WdColor.wdColorGray375)
            {
                doc.Application.ActiveWindow.Selection.Range.Select();
                doc.Application.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageHeader;
    
                doc.Application.Selection.HeaderFooter.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect1, text, "楷体", size,
                    MsoTriState.msoFalse, MsoTriState.msoFalse, 0, 0).Select();
                Microsoft.Office.Interop.Word.ShapeRange oShapeRange = doc.Application.Selection.ShapeRange;
                oShapeRange.Name = DateTime.Now.ToString("yyyyMMddhhmmssff") + RandomHelper.CreateRandomCode(8);//水印名称
    
                oShapeRange.Rotation = rotation;
                oShapeRange.LockAspectRatio = MsoTriState.msoTrue;
                oShapeRange.Height = doc.Application.CentimetersToPoints(height);
                oShapeRange.Width = doc.Application.CentimetersToPoints(width);
                oShapeRange.WrapFormat.AllowOverlap = -1;
                oShapeRange.WrapFormat.Side = Microsoft.Office.Interop.Word.WdWrapSideType.wdWrapBoth;
                oShapeRange.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapNone;
                oShapeRange.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionMargin;
                oShapeRange.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionMargin;
                oShapeRange.Left = (float)left;
                oShapeRange.Top = (float)top;
    
                oShapeRange.TextEffect.NormalizedHeight = MsoTriState.msoFalse;
                oShapeRange.Line.Visible = MsoTriState.msoFalse;
                oShapeRange.Line.Transparency = 1.0f;
                oShapeRange.Fill.Visible = MsoTriState.msoTrue;
                oShapeRange.Fill.Solid();
                oShapeRange.Fill.ForeColor.RGB = (Int32)color;
                oShapeRange.Fill.Transparency = transparency;
                doc.Application.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;
    
                //Microsoft.Office.Interop.Word.HeaderFooter hdr = doc.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
                //hdr.Range.Delete();
                //Microsoft.Office.Interop.Word.HeaderFooter ftr = doc.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
                //ftr.Range.Delete();
            }
    
        }
    }
    直接引用
  • 相关阅读:
    POJ 3261 Milk Patterns (求可重叠的k次最长重复子串)
    UVaLive 5031 Graph and Queries (Treap)
    Uva 11996 Jewel Magic (Splay)
    HYSBZ
    POJ 3580 SuperMemo (Splay 区间更新、翻转、循环右移,插入,删除,查询)
    HDU 1890 Robotic Sort (Splay 区间翻转)
    【转】ACM中java的使用
    HDU 4267 A Simple Problem with Integers (树状数组)
    POJ 1195 Mobile phones (二维树状数组)
    HDU 4417 Super Mario (树状数组/线段树)
  • 原文地址:https://www.cnblogs.com/shadow-wolf/p/11049980.html
Copyright © 2011-2022 走看看