我菜固我在

博客园 首页 新随笔 联系 订阅 管理

OleDbConnection ExcelConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+(new Comm.DoWeb()).GetFilePath(filePath.TempFilePath + filename)+";Extended Properties=Excel 8.0;");
   OleDbCommand ExcelCommand = new OleDbCommand();
   ExcelCommand.Connection = ExcelConnection;
   OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand);

   ExcelConnection.Open();
   //读取Excel表名
   DataTable ExcelSheets = ExcelConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
   for(int i=0;i<ExcelSheets.Rows.Count;i++)
   {
    string tableName = "["+ExcelSheets.Rows[i]["TABLE_NAME"].ToString()+"]";
    DataTable myTable=new DataTable();
    ExcelCommand.CommandText = @"SELECT * FROM "+SpreadSheetName;
    ExcelAdapter.Fill(myTable);
    ExcelConnection.Close();  
   }

posted on 2004-06-19 17:31  大侠(cer)  阅读(962)  评论(1编辑  收藏  举报