Excel 파일의 Sheet를 데이터 베이스처럼 읽어들입니다.
예제로 아래 소스를 읽어보세요 ^ ^
public DataTable GetDataTable()
{
string workSheet = "Sheet1$";
DataTable dtDataTable = new DataTable(workSheet);
string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=\"D:\\Test1.xls\";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
string sql = "SELECT * FROM [" + workSheet + "]";
conn.Open();
try
{
try
{
new OleDbDataAdapter(sql, conn).Fill(dtDataTable);
}
catch (Exception)
{
}
return dtDataTable;
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
dtDataTable.Dispose();
dtDataTable = null;
}
}
return dtDataTable;
}