Dim wordApp As New Word.Application()        Dim myDoc As Word.Document        Dim oTable As Word.Table        Dim rowIndex, colIndex As Integer        rowIndex = 1        colIndex = 0        wordApp.Documents.Add()        myDoc = wordApp.ActiveDocument        Dim Table As New DataTable()        Table = CreaTable()        oTable = myDoc.Tables.Add(Range:=myDoc.Range(Start:=0, End:=0), NumRows:=Table.Rows.Count + 1, NumColumns:=Table.Columns.Count)        '将所得到的表的列名,赋值给单元格        Dim Col As DataColumn        Dim Row As DataRow        For Each Col In Table.Columns            colIndex = colIndex + 1            oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName)        Next        '得到的表所有行,赋值给单元格        For Each Row In Table.Rows            rowIndex = rowIndex + 1            colIndex = 0            For Each Col In Table.Columns                colIndex = colIndex + 1                oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row(Col.ColumnName))            Next        Next        oTable.Borders.InsideLineStyle = 1        oTable.Borders.OutsideLineStyle = 1        wordApp.Visible = True这是代码,当运行时会出现:
异常详细信息: System.Runtime.InteropServices.COMException: 无法打开宏储存。源错误: 
行 86:         colIndex = 0
行 87: 
行 88:         wordApp.Documents.Add()
行 89: 
行 90:         myDoc = wordApp.ActiveDocument
 源文件: d:\inetpub\wwwroot\test\toword.aspx.vb    行: 88 堆栈跟踪: 
[COMException (0x800a175d): 无法打开宏储存。]
   Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) +0
   test.toword.Button1_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\test\toword.aspx.vb:88
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1263 我也添加了引用word, 不过是9.0的到是

解决方案 »

  1.   

    http://dotnet.aspx.cc里面有此种方法。
      

  2.   

    谢谢大哥,但是我还是有问题啊,因为它说无法打开宏存储无法打开宏储存。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Runtime.InteropServices.COMException: 无法打开宏储存。源错误: 
    行 41:         Dim missing As Object = System.Reflection.Missing.Value
    行 42:         Dim oWordApp As Word.ApplicationClass = New Word.ApplicationClass()
    行 43:         Dim oWordDoc As Word.Document = oWordApp.Documents.Add(missing, missing, missing, missing)
    行 44:         oWordDoc.Activate()
    行 45:         oWordApp.Selection.TypeText("This is the text")
     源文件: d:\inetpub\wwwroot\test\1.aspx.vb    行: 43 堆栈跟踪: 
    [COMException (0x800a175d): 无法打开宏储存。]
       Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) +0
       test._1.Button2_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\test\1.aspx.vb:43
       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain() +1263 
    还请大哥说说是怎么回事
      

  3.   

    是没有权限,要在Web.config 模拟一个超级用户   <identity impersonate="true" userName="SUZHOU\administrator" password="aimin" />