日期:2014-05-17 浏览次数:20456 次
public DataTable InputExcel(string xlsName, string TableName, string tablename2)
{
try
{
//获取到上传的Excel
string ThePath = Server.MapPath("../") + "UpLoad\\" + xlsName;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ThePath + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
string strExcel = "";
OleDbDataAdapter myCommand = null;
if (tablename2.Length > 0 && !tablename2.Equals(string.Empty))
{
TableName = tablename2;
}
strExcel = "select * from [" + TableName + "$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
DataTable dt = new DataTable();
myCommand.Fill(dt);
conn.Close();
return dt;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
if (dt.Rows.Count > 0)
{
this.GridView1.DataSource = inputdt;
&n