获取Excel工作表的列名称
问题描述:
HI ..
i希望在asp.net中获取excel表的列名,
我应该怎么做?
谢谢
HI..
i want to fetch column names of excel sheet in asp.net,
how should i do this?
thanks
答
这个想法对你有帮助!
从ASP.NET中的Excel文件(.xls)读取数据 [ ^ ]
This think will help you !
Read Data From an Excel File (.xls) in ASP.NET[^]
很高兴看到这个问题很简单,因为我最近在Excel工作表上完成了项目。
带我的工作。
您可以使用OleDbProvider
满足您的要求,而不是使用Interop
COM Componant。
这里代码来了。
Nice to see this Question it''s easy as I have recently accomplished project on Excel Worksheet.
Take my Work.
You could probably useOleDbProvider
to meet to your requirement rather the usingInterop
COM Componant.
Here the Code Goes.
protected void btnUpload_Click(object sender, EventArgs e)
{
OleDbConnection objConnection = new OleDbConnection(ConnectionString());
objConnection.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + SheetName + "
,objConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(objCmdSelect);
DataTable Dt = new DataTable();
objAdapter.Fill(Dt);
objConnection.Close();
}
private 字符串 ConnectionString()
{
return @ Provider = Microsoft。 Jet.OLEDB.4.0; +
@ 数据源= + fupdControl.PostedFile.FileName + ; +
@ 扩展属性= Excel 8.0;;
}
", objConnection); OleDbDataAdapter objAdapter = new OleDbDataAdapter(objCmdSelect); DataTable Dt = new DataTable(); objAdapter.Fill(Dt); objConnection.Close(); } private String ConnectionString() { return @"Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=" + fupdControl.PostedFile.FileName + ";" + @"Extended Properties=Excel 8.0;"; }
这里输入 SheetName
和 ExcelFileLocation
它会将该表的所有数据检索到数据表中,数据表的列名将是表的列名。
http://www.codeguru.com/forum/archive/index.php /t-388883.html [ ^ ]
请 投票 或 接受答案 如果有帮助。
Here input the SheetName
and ExcelFileLocation
it will retrieve all the data of that sheet into datatable, the column name of the datatable will be the column name of the Sheet.
http://www.codeguru.com/forum/archive/index.php/t-388883.html[^]
Please Vote or Accept Answer if it Helped.