c#如何确定找到excel表中的某个特定字符,并确定它的是哪行哪列?谢谢高手!给个代码例子

如题所述

方法大致如下:
//查询数据相等行和列的方法
public static List<string> FindData(DataTable dtTable, string strValue)
{
List<string> list = new List<string>();
string strInfo = string.Empty;
String value;
bool compareRes = true; //比较是否相同
int count = dtTable.Rows.Count;
for (int i = 0; i < count; i++)
{
for (int j = 0; j < dtTable.Columns.Count; j++)
{
//循环比较列的值是否相等
value = dtTable.Rows[i][j].ToString().Trim(); //值
if (strValue.Equals(value)) //相等
{
compareRes = true;
}
else
{
compareRes = false;
continue;
}

if (compareRes == true)
{
strInfo = string.Format("数据和表的行:{0},列:{1}的数据相等!", i + 2, j + 1);
list.Add(strInfo);
}
}
}
return list;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-02-07
将EXCEL表中的数据读进数据库中的某张表(读入前先对这张表进行清空操作),然后再用双重循环语句,从数据库中读这张表的数据,如果数据值==这个特定字符,就将循环变量的值,也就是它的行号和列号取出来即可
第2个回答  2012-02-07
读出来放到datatable,然后遍历datatable找吧。
相似回答