C#:怎样直接从excel中提取数据(急!!!)

来源:百度知道 编辑:UC知道 时间:2024/05/12 18:45:25
我看过网上很多方法基本上都比较复杂,我们头说可以直接从excel中提取数据,高手指教下.谢谢!
刚有报错说找不到可安装的ISAM可能会是什么原因!还有能解释下你OleDbDataAdapter里那段查询里的Sheet$代表什么意思不?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=e:\\Book1.xls;" + "Extended Properties=Excel 8.0;";
OleDbConnection con = new OleDbConnection(strConn);
OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]", con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];