excel.Workbooks.Open(filePath,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
好象不行,我装的是office2000

解决方案 »

  1.   

    比如:System.Diagnostics.Process.Start(@"C;\a.xls");
      

  2.   

    用OleDb不用装Office// 取Excel文件中的数据放到DataSet中
    private DataSet GetData()
    {
    DataSet ds = new DataSet();
    OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + this.tbFileName.Text + ";Extended Properties=Excel 8.0;");
    conn.Open();
    DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] {null, null, null, "TABLE"});
    ds.Tables.Clear();
    string sql = "";
    try
    {
    this.dataGrid.DataSource = null;
    this.cbSheet.Items.Clear();
    for(int i = 0 ; i < schemaTable.Rows.Count ; i ++)
    {
    string tableName = "[" + schemaTable.Rows[i]["TABLE_NAME"].ToString() +"]";
    if(tableName.IndexOf("Print_Titles") >= 0)
    {
    // 有时多出带Print_Titles的Sheet,我不知道为什么,把它过滤出去就行了!
    continue;
    }
    sql = "SELECT * FROM " + tableName;
    OleDbDataAdapter ada = new OleDbDataAdapter(sql, conn);
    ada.Fill(ds, tableName);
    }
    }
    catch(Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }
    return ds;
    }
      

  3.   

    我在用chinasdp() 的方法,只是open以后用的dataadapter帮定到dataset,但在open的时候总是提示找不到sql数据库啊。
      

  4.   

    谢谢大家热心解答,怪我没说明清楚,我只是想在C#程序中用Excel程序打开一个保存在硬盘上的Excel文件,并运行起来。我试过 System.Diagnostics.Process.Start方法,但提示说“不能访问...xls”,是为什么呢?/
      

  5.   

    回 s5689412(华君)
    路径没有问题,打开其他象记事本文件就可以的
    文件属性也没问题 
     可以通过设定System.Diagnostics.Process.Start方法的一些参数解决吗 
      

  6.   

    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Threading;
    using System.Windows.Forms;namespace OpenFile
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : Form
    {
    private Button button1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private Container components = null;
    private TextBox textBox1; private OpenFileDialog openFileDialog1; public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
    this.textBox1 = new System.Windows.Forms.TextBox();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
    this.button1.Location = new System.Drawing.Point(88, 72);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // textBox1
    // 
    this.textBox1.Location = new System.Drawing.Point(16, 24);
    this.textBox1.Name = "textBox1";
    this.textBox1.Size = new System.Drawing.Size(192, 20);
    this.textBox1.TabIndex = 1;
    this.textBox1.Text = "";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(232, 117);
    this.Controls.Add(this.textBox1);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private string path;
    private void button1_Click(object sender, EventArgs e)
    {
    this.openFileDialog1.Filter ="ExcelFile(*.xls)|*.xls|AllFiles(*.*)|(*.*)";
    DialogResult  dialogResult = this.openFileDialog1.ShowDialog();
    if(dialogResult == DialogResult.OK)
    {
    path = this.textBox1.Text = this.openFileDialog1.FileName ;
    Thread thread= new Thread(new ThreadStart(OpenExcelFile ) ) ;
    thread.Start();

    }

    }
    private void OpenExcelFile()
    {
    Process process = new Process() ;
    process.StartInfo.FileName = path;
    process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
    process.Start();
    }
    }
    }
    我自己编的,能运行。