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中的数据
///
/// 保存的路径
/// 上传控件
///
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
}