如何使用c#查找excel的非空列? [英] How To find non empty column of excel using c# ?

查看:132
本文介绍了如何使用c#查找excel的非空列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助

i只想获取那些有数据的excel列。

当我获取所有列时我得到错误而excel适配器填充数据集ExcelAdapter.Fill( ExcelDataSet);

please help
i want to fetch only those column of excel having data.
when i am fetching all column i get error while excel adapter fill dataset ExcelAdapter.Fill(ExcelDataSet);"

Error is "to many value"



所以我想获取那些在excel中有数据的列。

提前感谢

我的代码是




so i want to fetch those column having data in excel.
thanks in advance
my code is

OleDbConnection con = null;
string FilePath = Server.MapPath(Strfilename);
string FileExt = System.IO.Path.GetExtension(FilePath);
if (FileExt == ".xls")
{
con = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + FilePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"");
}
con.Open();
DataTable dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
Session["Dtexl"] = dt;
if (dt.Rows.Count > 0)
{
string getExcelSheetName = dt.Rows[0]["Table_Name"].ToString();
OleDbCommand ExcelCommand = new OleDbCommand(@"SELECT * FROM [" + getExcelSheetName + @"]", con);
OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand);
DataSet ExcelDataSet = new DataSet();
ExcelAdapter.Fill(ExcelDataSet);

推荐答案

hi,



是你的数据表包含超过10,000(一万行)的值,或者当你得到的是完全错误时。


is your Data table Contains over values like more the 10000(ten thousand rows ) or else when u get is error exactly.


这篇关于如何使用c#查找excel的非空列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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