asp.net操作word

一.介绍理论

现在讲的“宏”是只是针对OFFICE中的。

 :能自动执行某种操作的命令统称为。

VBA:是指Visual Basic for Application。它是在Office中使用的宏语言,主要为了增强WordExcel等软件的自动化能力。VBA的语法类似VB,但提供了很多VB中没有的函数和对象,这些函数、对象都是针对Office应用的。

二.在OFFICE中利用宏

宏在OfficeWord)中的应用

                
 

具――宏――录制新宏

然后进行一个操作。比如:查入一张图片 然后“停止宏的录制”

工具――宏――宏…--查看
宏代码:Sub Macro1()
 Macro1 Macro
'
宏在 2004-11-26 用户46 录制'
 Selection.InlineShapes.AddPicture FileName:= _
       "
C:/Documents and Settings/Administrator/桌面/2003121512223366481.bmp", LinkToFile:=False, SaveWithDocument:=True
End Sub
代码

 

 

以上只是介绍了宏的最简单的用法。宏还可以操作工具栏。小菜鸟本身也只是会一些简单的。

三.在.NET中使用宏的要求(系统和Web.config

如果要正常操作Word Com组件的话,必须要给用户赋上足够的权限的,以下是我找问高手,和上网上查到的。如果不这样的话,应该不能操作Word,会出现异常

.运行Dcomcnfg.exe
2.组件服务――计算机――我的电脑――DCOM配置――找到microsoft word 文档
.点击属性
.选择安全性
.选定使用自定义访问权限使用自定义启动权限
.分别编辑权限,添加ASPNET,VS Developers,Debugger User
.选择身份标识,在选定交互式用户即可
. Web.config里加 <identity impersonate="true"/>



四.一个在.NET使用宏的例子

先引入Microsft Word 11.0 Object Library

 

 

private   void  button2_Click( object  sender, System.EventArgs e)
        
{
            
object filename = @"C:/Inetpub/wwwroot/TestWebApp/test.doc";//文件名
            Word.Application a =  new Word.ApplicationClass();//建立一个Word程序对像
            object Nothing = System.Reflection.Missing.Value;//空值
            Word.Document b = a.Documents.Open(ref filename,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);//建立一个Word文档对像            

            
//其实这步就是执行了这个宏
            a.Selection.InlineShapes.AddPicture(@"C:/Documents and Settings/Administrator/桌面/2003121512223366481.jpg",ref Nothing,ref Nothing,ref Nothing);
            
//Selection.InlineShapes.AddPicture FileName:= "C:/Documents and Settings/Administrator/桌面/2003121512223366481.bmp", LinkToFile:=False, SaveWithDocument:=True   End Sub    b.Save();//保存
            b.Close(ref Nothing,ref Nothing,ref Nothing);//关闭Word文档
            a.Quit(ref Nothing,ref Nothing,ref Nothing);//退出Word程序
        }

 

OK~~~~~~去看一下Word文件中,是不是多了一张图片呀~!!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值