using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
///
/// Excel操作基類
///
public class ExcelObj
{
public ExcelObj()
{
}
#region 保存並返回Excel中的數據
///
/// 保存並返回Excel中的數據
///
///
保存的路徑
///
上傳控件
/// c public static DataSet SaveAndReturn(string SavePath, FileUpload myFileUpload)
{
DataSet myDs = new DataSet();
string fileName = myFileUpload.FileName;
if (fileName != "")
{
try
{
myFileUpload.SaveAs(SavePath + "\\" + fileName);
}
catch (Exception ee)
{
throw new Exception(ee.ToString());
}
string mystring = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '" + SavePath + "//" + fileName + "';Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection(mystring);
OleDbDataAdapter myDa = new OleDbDataAdapter("select * from [Sheet1$]", cnnxls);
myDa.Fill(myDs);
}
return myDs;
}
#endregion
}