fileupload列出上传Excel文件后,DropDownList自动列出Excel文件中的所有表名?
fileupload列出上传Excel文件路径与文件名后,DropDownList自动列出Excel文件中的所有表名?
如何实现。请教各位老师们!!!!
[解决办法]
object missing=Missing.Value;
Excel.Application excel=new Excel.Application ( );
excel.Application.Workbooks.Open(FileName,missing,missing,missing,missing,
missing,missing,missing,missing,missing,missing, missing,missing, missing,missing);
excel.Visible = false;
for(int i=0 ;i<excel.Worksheets.Count;i++)
{
MessageBox.Show(((Excel.Worksheet)excel.Worksheets[i+1]).Name);
}
string str= string.Format(@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0 ",path);
using(OleDbConnection conn = new OleDbConnection(ConnString))
{
conn.Open();
DataTable schemaTable=conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE "});
conn.Close();
}
[解决办法]
List<string> list = new List<string>();string str= string.Format(@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0 ",path); using(OleDbConnection conn = new OleDbConnection(ConnString)){conn.Open(); DataTable schemaTable=conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE "}); foreach(DataRow row in schemaTable.Rows){ list.Add(row[2],row[2]);}conn.Close(); void AddDropDown(){ foreach(string s in list){ DropDwonList1.Items.Add(s,s);}}