zoukankan      html  css  js  c++  java
  • 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");
        }
    
    
    
    
    
    
         
    
    
    
    
    
    
    }
    

      

  • 相关阅读:
    redis简单使用及连接池
    初始Redis
    redis安装教程
    .whel文件的打开方式
    xpath选择器的使用,selenium使用
    爬虫之bs4的使用,之爬取汽车之家新闻,之代理池的搭建
    爬虫基础 之 爬取梨视频 模拟登陆 爬取妹子图
    git基本使用

    re模块正则表达式
  • 原文地址:https://www.cnblogs.com/mqingqing123/p/14234904.html
Copyright © 2011-2022 走看看