日期:2014-05-18 浏览次数:20950 次
strName = this.FileUpload1.PostedFile.FileName; txt0.Visible = true; txt0.Text += "<br />上传成功!开始判断导入文件名:" + strName + "!!!<br />"; #region 开始判断文件名 //if (this.FileUpload1.PostedFile.FileName != "") if (strName != "") { #region 开始导入工作薄名列表 string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strName + ";Extended Properties=Excel 8.0"; this.lbFileUpload1.Text = strConn; //aaa = strConn; //链接Excel OleDbConnection cnnxls = new OleDbConnection(strConn); OleDbCommand cmd = new OleDbCommand(); if (cnnxls.State == ConnectionState.Open) { cnnxls.Close(); cnnxls.Dispose(); cmd.Dispose(); } cnnxls.Open(); //DataTable schemaTable = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); DataTable schemaTable = cnnxls.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); txt0.Text += schemaTable.Rows.Count + "!!!<br />"; cnnxls.Close(); //读取Excel里面有 表Sheet1 if (schemaTable.Rows.Count > 0) { for (int i = 0; i < schemaTable.Rows.Count; i++) { string BiaoMC = schemaTable.Rows[i]["TABLE_NAME"].ToString(); ListItem li = new ListItem(BiaoMC, schemaTable.Rows[i]["TABLE_NAME"].ToString()); this.ddBiaoMC.Items.Insert(i, li); } } ............... } #endregion