但2003與2007 需call 不同的function
Sample:
FileStream stream = File.Open(FileUploader.PostedFile.FileName, FileMode.Open, FileAccess.Read);
//副檔名,區分是2003版 or 2007版
var arr = FileUploader.FileName.Split('.');
IExcelDataReader excelReader;
if(arr.Count()==2)
{
if(arr[1]=="xlsx")
//2007
excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
else
{
//2003
excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
}
DataSet result = excelReader.AsDataSet();
//取出Excport成Datatable的Excel資料
DataTable table = result.Tables[0];
//關閉連線
excelReader.Close();
}
參考資料:
http://exceldatareader.codeplex.com/
http://www.dotblogs.com.tw/yc421206/archive/2011/03/13/21819.aspx