日期:2014-05-17 浏览次数:20446 次
private DataTable ExcelToDataTable(string FilePath)
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + FilePath + ";Extended Properties='Excel 8.0; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [ItemLocation$]", strConn);
DataSet myDataSet = new DataSet();
try
{
myCommand.Fill(myDataSet);
// 取出数据后删除文件
// 删除已存在的文件
if (File.Exists(FilePath))
{
File.Delete(FilePath);
}
}
catch
{
}
return myDataSet.Tables[0];
}
System.Web.UI.WebControls.GridView gvExport = null;
&nbs