日期:2014-05-17 浏览次数:21120 次
/// <summary>
/// Excel数据连接字符串
/// </summary>
private const string EXCELConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=YES;IMEX=1';Data Source=";
/// <summary>
/// 读取Excel到DataTable
/// </summary>
/// <param name="Path"></param>
public static System.Data.DataTable ReadExcelToDataTable(string Path)
{
DataSet ds = new DataSet();
string queryString = "SELECT * FROM [Sheet1$] where 学号 <> ''";
string path = EXCELConnString + Path;
using (OleDbConnection connection = new OleDbConnection(path))
{
try
{
OleDbCommand oleCommand = new OleDbCommand(queryString, connection);
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
OleDbDataAdapter oleAdapter = new Ole