日期:2014-05-17 浏览次数:20842 次
OleDbConnection conn = new OleDbConnection();
try
{
string FilePaths = FilePath;
// ' F:\G2000-S041 G2000MEN GMF MASS NON-CHINA SP-2012 ORDER FORM.xls
dynamic FileWZ = FilePaths.LastIndexOf(".");
//文件的位置
dynamic File_H_Z = FilePaths.Substring(FileWZ);
//得到后缀
if (File_H_Z == ".xls")
{
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + FilePath + ";Extended Properties ='Excel 8.0;HDR=YES;IMEX=1'";
}
if (File_H_Z == ".xlsx")
{
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " + FilePath + ";Extended Properties ='Excel 12.0;HDR=YES;IMEX=1'";
}
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
//return conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] {null,null,null,"TABLE"});
OleDbDataAdapter adapter = new OleDbDataAdapter("select * from [Sheet1$]", conn);
DataSet myDataSet = n