苏州三木软件科技有限公司

 找回密码
 立即注册
搜索
热搜: 活动
查看: 1127|回复: 1

数据管理中如何定位行数据

[复制链接]

25

主题

46

帖子

178

积分

注册会员

Rank: 2

积分
178
发表于 2023-4-1 14:57:26 | 显示全部楼层 |阅读模式
本帖最后由 李泰蜜 于 2023-4-1 15:06 编辑

知道某行的数据其中包含1128,我需要快速定位到这个数据在哪一列,并且查询结果中会提示是否有重复数据。
回复

使用道具 举报

25

主题

313

帖子

2077

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
2077
QQ
发表于 2023-4-1 15:04:58 | 显示全部楼层
添加一个内部函数,比如就叫“定位行数据”,然后输入下面的代码

  1. string strFind=Args[0].CType<string>("");
  2. List<string> lst=new List<string>();
  3. int intBegin=Proj.CurrentSmGrid.Selection.c1;
  4. int intEnd=Proj.CurrentSmGrid.Selection.c2;
  5. for (int i = intBegin; i <= intEnd; i++)
  6. {
  7.         string strCellValue=Proj.CurrentSmGrid[Proj.CurrentSmGrid.Selection.r1,i].CType<string>("");
  8.         if(strCellValue.Contains(strFind))
  9.         {
  10.                 lst.Add(i.ToString());
  11.         }        
  12. }
  13. if(lst.Count>1)
  14. {
  15.         MessageBox.Show("此次查找结果有"+lst.Count);
  16. }
  17. if(lst.Count>0)
  18. {
  19.         Proj.CurrentSmGrid.Select(Proj.CurrentSmGrid.Selection.r1,lst[0].CType<int>(0),true);
  20. }
  21. return "";
复制代码

Vb.net的代码
  1.     Dim strFind As String = Args(0)
  2.     Dim lst As List(Of String) = New List(Of String)()
  3.     Dim intBegin As Integer = Proj.CurrentSmGrid.Selection.c1
  4.     Dim intEnd As Integer = Proj.CurrentSmGrid.Selection.c2
  5.     For i As Integer = intBegin To intEnd
  6.         Dim strCellValue As String = Proj.CurrentSmGrid(Proj.CurrentSmGrid.Selection.r1, i).ToString()
  7.         If strCellValue.Contains(strFind) Then
  8.             lst.Add(i.ToString())
  9.         End If
  10.     Next
  11.     If lst.Count > 1 Then
  12.         MessageBox.Show("此次查找结果有" & lst.Count)
  13.     End If
  14.     If lst.Count > 0 Then
  15.         Proj.CurrentSmGrid.Select(Proj.CurrentSmGrid.Selection.r1, lst(0), True)
  16.     End If
  17.     Return ""
复制代码
然后在调用的时候使用
Proj.Functions.Execute("定位行数据","1128")

先用鼠标点击行标题,以实现整行选择,然后在命令窗口中执行上面的代码,即可在当前行中查找包含1128这个数值的单元格,如果单元格里面包含要查找的数据的,则会被计数。如果结果只查找到一个,则直接定位到相应的单元格,如果查找结果有多个,则会提示在当前行一共找到几个结果,然后再定位到第一个查找到的单元格。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|苏州三木软件科技有限公司 ( 苏ICP备2022038390号 )

苏公网安备 32058502010732号

GMT+8, 2024-10-3 00:25 , Processed in 0.075314 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表