Any simple way to search value in table?

Aronax

Client
Регистрация
29.01.2015
Сообщения
201
Благодарностей
59
Баллы
28
I need Zenno to search for a specific value in a specific column of a 100k rows excel table.

The only way to do this seems to be a a manual mode where you ask zenno to take each cell on the specific column and compare the value of that cell with the value you need to find. If the values are not the same, Zenno needs to move on to the next cell in that column and continue the loop. This is very time consuming and I need it do it faster.

I've found these C macros:
http://zennolab.com/discussion/threads/search-in-list-and-tables-via-c-macro.10733/

...but they are not very helpful in my situation because they only 'confirm' if the specified value has been found in the table (and they indeed work much much faster).

What I need after the specified value is found in the specified column of the excel table, is to take its row number and use it in order to take another element on that specific row.

Thanks for your thoughts.
 

Tobbe

Client
Регистрация
01.08.2013
Сообщения
428
Благодарностей
148
Баллы
43
You refer to this?

JavaScript:
// take text for search from a variable
var textContains = project.Variables["tableSearchTextContains"].Value;
// get table for search
var sourceTable = project.Tables["SourceTable"];
// search in each row
lock(SyncObjects.TableSyncer)
{
    for(int i=0; i < sourceTable.RowCount; i++)
    {
        // read a row (array of cells)
        var cells = sourceTable.GetRow(i).ToArray();
        // loop through all cells
        for (int j=0; j < cells.Length; j++)
        {
            // check if cell contains specified text, if there are matches return "yes"
            if (cells[j].Contains(textContains))
                return "yes";
        }
    }
}
// if nothing found return "no"
return "no";
There's already a counter keeping track of the rows the script process in that loop. So instead of returning yes/no, you can tell it to return the current count of the variable instead.
JavaScript:
// take text for search from a variable
var textContains = project.Variables["tableSearchTextContains"].Value;
// get table for search
var sourceTable = project.Tables["SourceTable"];
// search in each row
lock(SyncObjects.TableSyncer)
{
    for(int i=0; i < sourceTable.RowCount; i++)
    {
        // read a row (array of cells)
        var cells = sourceTable.GetRow(i).ToArray();
        // loop through all cells
        for (int j=0; j < cells.Length; j++)
        {
            // check if cell contains specified text
            if (cells[j].Contains(textContains))
                // If there's a match then return the current line #(zero based)
                return i;
        }
    }
}
// if nothing found return "no"
return "no";
Notice the " return i " (variable) instead of " return 'yes' " (a string/plain text). Wasn't able to highlight it within CODE tags :(
 
Последнее редактирование:
  • Спасибо
Реакции: PHaRTnONu и Aronax

Aronax

Client
Регистрация
29.01.2015
Сообщения
201
Благодарностей
59
Баллы
28
Good idea!
 

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
Maby im just a moron but i can not get this to work for me
i dont even get a return of no in my varible

JavaScript:
var textContains = project.Variables["{-Variable.TEXTPROCESSING-}"].Value;
// get table for search
var sourceTable = project.Tables["Table1"];
// search in each row
lock(SyncObjects.TableSyncer)
{
    for(int i=0; i < sourceTable.RowCount; i++)
    {
        // read a row (array of cells)
        var cells = sourceTable.GetRow(i).ToArray();
        // loop through all cells
        for (int j=0; j < cells.Length; j++)
        {
            // check if cell contains specified text
            if (cells[j].Contains(textContains))
                // If there's a match then return the current line #(zero based)
                return i;
        }
    }
}
// if nothing found return "no"
return "no";
 

Tobbe

Client
Регистрация
01.08.2013
Сообщения
428
Благодарностей
148
Баллы
43
  • Спасибо
Реакции: PHaRTnONu

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
/slap own face
sorry
working fine now just left var name didn't copy over the macro copy var. working great
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)