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提示)
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提示)
解决方案 »
- 关于窗体的调用。请查看内文谢谢
- 如何让Winform的TextBox失去焦点?
- mediaplayer在两窗口间的调用问题
- 局域网内如何通过机器的IP地址获取该机器的MAC地址?
- 关于DATASET中逐行读出数据,返回读出这行数据中的一列的值,再逐行存入SQL数据库的问题
- 为什么 System.IO.Directory.Delete(targetpath,true); 删除不了目录下的只读文件?
- 如何实现以下功能。
- C# DataGridViewComboBoxCell获取下拉框中的内容
- 怎样判断输入的是数字还是字符???
- 请问通过窗体的TransparencyKey,如何制作不规则窗体?
- 请问一下时候在.net2005里面把CheckForIllegalCrossThreadCall置为False会有什么影响吗?比如内存错误或者Win32exception?
- 如何把datareader中得知取出放到label或textbox中,我知道VB的,但不知道C#语法是什么
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();
}
{
object missing = System.Reflection.Missing.Value;
oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing); oDoc.Activate();
}
还有 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
}
}我是新手麻烦你们了
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()即可.
我自己也弄弄看
你做WEBFORM的程序可能有些东西一样吧,但可能考虑权限的问题.