• word添加水印,.NET执行宏


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Word=Microsoft.Office.Interop.Word;
    using Microsoft.Vbe.Interop;
    public partial class word : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
    
    
        protected void Button1_Click(object sender, EventArgs e)
        {
    
            object srcFileName = Server.MapPath("b.doc"); 
            object obj = true; 
    
    
             object Nothing = System.Reflection.Missing.Value;
    
             Word.ApplicationClass wordAppObj = new Word.ApplicationClass(); 
             Word.Document WordDoc = null;
             WordDoc = wordAppObj.Documents.Open(ref srcFileName, 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);
    
    
    
             var project = WordDoc.VBProject;
             var module = project.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule);
    
             var script = string.Format(
             @"
              Sub 宏1()
     
        ActiveDocument.Sections(1).Range.Select
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        Selection.HeaderFooter.Shapes.AddTextEffect(  PowerPlusWaterMarkObject2859093, ""ASAP123654"", ""等线"", 1, False, False, 0,0).Select
        Selection.ShapeRange.Name = ""PowerPlusWaterMarkObject2859093""
        Selection.ShapeRange.TextEffect.NormalizedHeight = False
        Selection.ShapeRange.Line.Visible = False
        Selection.ShapeRange.Fill.Visible = True
        Selection.ShapeRange.Fill.Solid
        Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)
        Selection.ShapeRange.Fill.Transparency = 0.5
        Selection.ShapeRange.Rotation = 315
        Selection.ShapeRange.LockAspectRatio = True
        Selection.ShapeRange.Height = CentimetersToPoints(3.44)
        Selection.ShapeRange.Width = CentimetersToPoints(17.21)
        Selection.ShapeRange.WrapFormat.AllowOverlap = True
        Selection.ShapeRange.WrapFormat.Side = wdWrapNone
        Selection.ShapeRange.WrapFormat.Type = 3
        Selection.ShapeRange.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
        Selection.ShapeRange.RelativeVerticalPosition =  wdRelativeVerticalPositionMargin
        Selection.ShapeRange.Left = wdShapeCenter
        Selection.ShapeRange.Top = wdShapeCenter
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    
       ActiveDocument.Save
    End Sub 
    
    ");
    
             module.CodeModule.AddFromString(script);  
             wordAppObj.Run("宏1");
             WordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
             wordAppObj.Quit(ref Nothing, ref Nothing, ref Nothing);
             Response.Write("ok");
        }
    
    
    
    
    
    
         
    
    
    
    
    
    
    }
    

      

  • 相关阅读:
    myfocus官方网站已经挂掉,相关下载已经从googlecode转到网盘
    [综合]visio2013安装提示找不到Office.zh_cnofficeMUI.mis officemui.xml
    技巧分享:解决Word 2010当中“分页符”造成的空白行
    房贷计算器代码2.0
    房贷计算器代码
    图解-JS普通函数跟箭头函数中this的指向问题
    完全基于net core容器的超级轻量化的Quartz,支持类似net core mvc的过滤器,附过滤器实现源码
    net下的高性能轻量化半自动orm+linq的《SqlBatis》
    轻量级ORM《sqlcommon》第一个版本发布了!!!
    从0开始编写dapper核心功能、压榨性能、自己动手丰衣足食
  • 原文地址:https://www.cnblogs.com/mqingqing123/p/14234904.html
Copyright © 2020-2023  润新知