首页 > Web开发 > 详细

word添加水印,.NET执行宏

时间:2021-01-05 12:20:44      阅读:42      评论:0      收藏:0      [点我收藏+]
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");
    }






     






}

  

word添加水印,.NET执行宏

原文:https://www.cnblogs.com/mqingqing123/p/14234904.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!