user office primary interop 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 System.Reflection;namespace OpenDoc { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); //Make sure that Word will be visible. app.Visible=true; // Setting these variables to Missing.Value is comparable // to not providing a value for an optional parameter in VB. // This gets the default behavior. string path=Page.Request.MapPath(""); object fileName = path + "/example3.doc"; object optional = Missing.Value;
请问能把你的例子给我一份吗?谢谢~~~~~
[email protected] 或
[email protected]
请问能把你的例子给我一份吗?谢谢~~~~~
[email protected]
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 System.Reflection;namespace OpenDoc
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
//Make sure that Word will be visible.
app.Visible=true;
// Setting these variables to Missing.Value is comparable
// to not providing a value for an optional parameter in VB.
// This gets the default behavior.
string path=Page.Request.MapPath("");
object fileName = path + "/example3.doc";
object optional = Missing.Value;
Microsoft.Office.Interop.Word._Document doc = app.Documents.Open2000( ref fileName,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional);
object first=0;
object last=doc.Characters.Count;
doc.Range(ref first, ref last).Select();
doc.Range(ref first, ref last).Cut();
fileName += "_new";
doc.SaveAs2000( ref fileName,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional,
ref optional);
object saveChanges = true;
app.Quit(ref saveChanges, ref optional, ref optional);
}
}
}
My web page works well, no error, no warning.