已解决:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Excel;
using ExcelApplication = Excel.Application;
using System.Reflection;namespace hlt
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
//private AxSHDocVw.AxWebBrowser axWebBrowser2;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.ToolBar toolBar1;
private _Worksheet worksheet;
private AxSHDocVw.AxWebBrowser axWebBrowser2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
string strFileName=@"d:\a.xls";
Object refmissing=System.Reflection.Missing.Value;
axWebBrowser2.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing);
//axWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing);
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null) 
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.axWebBrowser2 = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser2)).BeginInit();
this.SuspendLayout();
// 
// mainMenu1
// 
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  this.menuItem1});
// 
// menuItem1
// 
this.menuItem1.Index = 0;
this.menuItem1.Text = "存盘";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
// 
// toolBar1
// 
this.toolBar1.DropDownArrows = true;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(804, 42);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
// 
// axWebBrowser2
// 
this.axWebBrowser2.Enabled = true;
this.axWebBrowser2.Location = new System.Drawing.Point(8, 64);
this.axWebBrowser2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axWebBrowser2.OcxState")));
this.axWebBrowser2.Size = new System.Drawing.Size(656, 384);
this.axWebBrowser2.TabIndex = 2;
// 
// Form1
// 
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(804, 466);
this.Controls.Add(this.axWebBrowser2);
this.Controls.Add(this.toolBar1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.axWebBrowser2)).EndInit();
this.ResumeLayout(false); }
#endregion private object oApplication=null;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
//Application.Run(new Form1());
System.Windows.Forms.Application.Run(new Form1());
} private void axWebBrowser2_Enter(object sender, System.EventArgs e)
{
string strFileName=@"d:\a.xls";
Object refmissing=System.Reflection.Missing.Value;
axWebBrowser2.Navigate(strFileName, ref refmissing , ref refmissing , ref refmissing , ref refmissing);
axWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing); }
public void axWebBrowser2_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
Object o = e.pDisp;
Object oDocument = o.GetType().InvokeMember("Document",BindingFlags.GetProperty,null,o,null);
oApplication = o.GetType().InvokeMember("Application",BindingFlags.GetProperty,null,oDocument,null);
//Object oName = o.GetType().InvokeMember("Name",BindingFlags.GetProperty ,null,oApplication,null); //由于打开的是excel文件,所以这里的oApplication 其实就是Excel.Application
Excel.Application eApp =(Excel.Application)oApplication;//这样就可以象上文中所述来操作Excel了。
}
private void Form1_Load(object sender, System.EventArgs e)
{ } private void menuItem1_Click(object sender, System.EventArgs e)
{
//Excel.Application eApp =(Excel.Application)oApplication;
//Excel.Workbook oBook;
//_Worksheet worksheet; if (oApplication==null) return; ExcelApplication excel = (Excel.Application)oApplication; excel.Workbooks.Add(Missing.Value);
Worksheet worksheet = (Worksheet) excel.ActiveSheet; Missing a = Missing.Value;
worksheet.SaveAs("d:\\aa.xls",a,a,a,a,a,a,a,a,a);// worksheet.SaveAs(@"c:\a.xls",
// Missing.Value,
// Missing.Value,
// Missing.Value,
// Missing.Value,
// Missing.Value,
// Missing.Value,
// Missing.Value,
// Missing.Value);
} private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
//axWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref refmissing , ref refmissing);
}
}
}