读取:将Excel中的数据读入到 DataSet 中
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
class ExcelReader
{
private DataSet myData;
public ExcelReader(String Path)
{
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(strConn);
String strCom = "SELECT * FROM [Sheet1$]";
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
myData = new DataSet();
myCommand.Fill(myData, "[Sheet1$]");
myConn.Close();
}
public DataSet GetData()
{
return myData;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
class ExcelReader
{
private DataSet myData;
public ExcelReader(String Path)
{
String strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + ";Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(strConn);
String strCom = "SELECT * FROM [Sheet1$]";
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
myData = new DataSet();
myCommand.Fill(myData, "[Sheet1$]");
myConn.Close();
}
public DataSet GetData()
{
return myData;
}
}