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
好象不行,我装的是office2000
解决方案 »
- 请教一下使用泛型的问题.(我是小白)
- datagridview赋值无法显示 求助!!!
- datagridview排序后,checkbox列的选择状态都变成反选了
- 问个有点难度但似乎很简单的问题:关于dataset
- 请问我装的framework2.0中文版,可错误信息怎么都是英文?
- 如何DataView转成一个新的DataTable,急,请大虾帮忙
- 自定义控件
- 怎么更新日期会出错??
- 在c#中怎么用wmi来对dns加一条A记录?
- 大声疾呼!!!如何在IE中执行服务器端的可执行文件(*.exe)?
- 紧急求助:关于sql server 2000数据库安全的问题
- string(十进制数字字符组成)转化为long ,用什么?
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;
}
路径没有问题,打开其他象记事本文件就可以的
文件属性也没问题
可以通过设定System.Diagnostics.Process.Start方法的一些参数解决吗
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();
}
}
}
我自己编的,能运行。