• 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");
        }
    
    
    
    
    
    
         
    
    
    
    
    
    
    }
    

      

  • 相关阅读:
    Android -- BroadCastReceiver的简单使用
    iOS-UITextField 全面解析
    iOS判断对象相等 重写isEqual、isEqualToClass、hash
    iOS开发 之 不要告诉我你真的懂isEqual与hash!
    浅谈 Objective-C 下对象的初始化
    iOS学习之Object-C语言继承和初始化方法
    Objective-c 中如何重写父类的初始化方法
    OC学习篇之---类的初始化方法和点语法的使用
    iOS7实现带文本输入框的UIAlertView及获取TextField文本内容
    UIALertView的基本用法与UIAlertViewDelegate对对话框的事件处理方法
  • 原文地址:https://www.cnblogs.com/mqingqing123/p/14234904.html
Copyright © 2020-2023  润新知