获取Excel工作表的列名称 [英] Fetch column name of Excel sheet

查看:98
本文介绍了获取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 use OleDbProvider to meet to your requirement rather the using Interop 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.


这篇关于获取Excel工作表的列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆