using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;namespace word
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined book */ //Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application(); (到这行就运行不下去出现System.UnauthorizedAccessException提示)

解决方案 »

  1.   

    打开WORD:
    private Word.ApplicationClass oWordApplic;
    private Word.Document oDoc;
    public void Open(string strFileName)
    {
    object fileName = strFileName;
    object readOnly = false;
    object isVisible = true;
    object missing = System.Reflection.Missing.Value; oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref missing, 
    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, 
    ref missing, ref missing, ref missing); oDoc.Activate();
    }
      

  2.   

    谢谢!!你上面这个是打开WORD,我这里要创建一个WORD
      

  3.   

    还有我用VS2003 当我打到 oWord = new Word的时候按 "."没有出来Application(); 只有 ApplicationClass
      

  4.   

    public void New( )
    {
    object missing = System.Reflection.Missing.Value;
    oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing); oDoc.Activate();
    }
      

  5.   

    to 还有我用VS2003 当我打到 oWord = new Word的时候按 "."没有出来Application(); 只有 ApplicationClassweb程序默认运行用户是aspnet,所以你系统安装的office组件对于aspnet用户来说,不一定有使用权限。
      

  6.   

    谢谢你们!!那怎么样才能有呢!!
    还有 qyfjl() 
    我用你的给的代码,编译了一下出现这个错误代码是
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Word = Microsoft.Office.Interop.Word;
    using System.Reflection;namespace word
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    New(); }

    private Word.ApplicationClass oWordApplic;
    private Word.Document oDoc;
    public void New()
    {
    object missing = System.Reflection.Missing.Value;
    oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing);(出现未将对象引用设置到对象的实例。错误)
    oDoc.Activate();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }我是新手麻烦你们了
      

  7.   

    private Word.ApplicationClass oWordApplic;
    private Word.Document oDoc;
    public void New()
    {
    object missing = System.Reflection.Missing.Value;
    oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing);(出现未将对象引用设置到对象的实例。错误)
    oDoc.Activate();
    }把这个代码放到一个专门操作Word 的类里.
    最后再实例化这个类,再调用OPEN()即可.
      

  8.   

    如果有空的话:能不能帮忙做一个完整的页面,我已经搞了一天了!!谢谢qyfjl() 
    我自己也弄弄看
      

  9.   

    呵呵,我的代码是Winform的.
    你做WEBFORM的程序可能有些东西一样吧,但可能考虑权限的问题.