private void button1_Click(object sender, EventArgs e)
{
//string strExcel;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=e://1统计机报6.xls;Extended Properties=/"Excel 8.0;HDR=no;IMEX=1/"";
OleDbConnection conn = new OleDbConnection(strConn);
string strExcel = "";
OleDbDataAdapter myCommand = null;
ds = new DataSet();
strExcel = "select * from [机报-6$]";
try
{
conn.Open();
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(ds, "dtSource");
for (int i = 0; i <= 11; i++) //删除无用数据
{
ds.Tables[0].Rows[i].Delete();
}
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1].Delete();
ds.AcceptChanges();
dataGridView1.DataSource = ds.Tables[0];
//dataGridView1.Rows.Remove(dataGridView1.Rows[1]);
//return ds;
}
catch (Exception ex)
{
MessageBox.Show("导入出错:" + ex, "错误信息");
//return ds;
}
finally
{
conn.Close();
conn.Dispose();
}
}