• 导出的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();
            }
    
        }
    }
    直接引用
  • 相关阅读:
    Java【第二篇】基本语法之--进制、运算符
    Java【第一篇】基本语法之--关键字、标识符、变量及分类、数据类型及转换
    安装运行zookeeper的坑
    部署java应用的几种方式
    解决sudo用户找不到环境变量的问题
    Python装饰器详解
    filebeat开启自带模块收集日志如何辨别日志来源等
    使用elasticsearch7.3版本在一台主机上部署多个实例组建集群
    redis 集群搭建
    Kibana多用户创建及角色权限控制
  • 原文地址:https://www.cnblogs.com/shadow-wolf/p/11049980.html
Copyright © 2020-2023  润新知