2 Table process issue's

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
Ok So im trying to do a few things here.
1. return the row number based on a unique id inside the project variable UID
2. Dictate a dictionary of project variables and the corresponding columns they correlate to.
3. If text/data is present in the cell already ignore updating them UNLESS
a. In a few instances, say G H & M, they have a lot of stuff in them, and it may be necisiary to add data no present.
example DBWords has: red, blue, green but row 3 cell M has yellow, green, purple
The updated cell 3,M after would be yellow, green, purple, red, blue

I keep getting error saying row doesnt exist


Dictonary:
// get the unique ID to search for
var UID = project.Variables["UID"].Value;

// get the table to search in
var sourceGTable = project.GoogleSpreadsheets["Table1"];

// search for the row that contains the unique ID
lock(SyncObjects.TableSyncer)
{
    for(int i=0; i < sourceGTable.RowCount; i++)
    {
        // read a row from the table (it will be a cell array)
        var cells = sourceGTable.GetRow(i).ToArray();

        // loop through all cells
        for (int j=0; j < cells.Length; j++)
        {
            // check the content of the text in the cell, if there is a match, store the row number
            if (cells[j].Contains(UID))
            {
                var row = i;
                break;
            }
        }
    }
}

// if nothing is found, return "no"
if (row == null)
{
    return "no";
}

// list of variables to check, with the corresponding column letter
var variables = new Dictionary<string, string>()
{
    {"UNIX", "B"},
    {"Date", "C"},
    {"Title", "D"},
    {"URL", "E"},
    {"Master", "F"},
    {"DBno", "G"},
    {"tor", "H"},
    {"DBWords", "M"},

};

// loop through the variables
foreach (var variable in variables)
{
    // get the column for the current variable
    var column = variable.Value;

    // get the value of the variable
    var value = project.Variables[variable.Key].Value;

    // get the value in the cell for the current column and row
    var cellValue = sourceGTable.GetCell(row, column).Value;

    // check if the cell value matches the variable value
    if (cellValue == value)
    {
        // the values match, skip to the next variable
        continue;
    }

    // the values don't match, check if the cell value is a list of values
    if (cellValue.Contains(","))
    {
        // split the cell value into a list of values
        var values = cellValue.Split(",");

        // check if the new value is already in the list
        if (values.Contains(value))
        {
            // the value is already in the list, skip to the next variable
            continue;
        }

        // the value is not in the list, append it to the list
        values.Append(value);

        // join the list of values into a single string
        var newCellValue = string.Join(",", values);

        // write the new value back to the cell in the table
        sourceGTable.SetCell(row, column, newCellValue);
    }
    else
    {
        // the cell value is not a list of values, simply write the new value to the cell
        sourceGTable.SetCell(row, column, value);
    }
}
keep getting error's saying row doesnt exist but its returned.... so im very confused
any help here would be MUCH appreciated. I know it seems strange, but in reality my dictonary would be about 40 more entrys, so its a alot of passing back and forth i would rather avoid all those blocks if i can get this Table C# working propperly it would reduce my stub tremendously
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 770
Благодарностей
1 182
Баллы
113
You can always try to enclose any code in try catch blocks and see what errors you get.
Another idea is to print out logs what line is taken, then you will see at what line you get an error.
 

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
You can always try to enclose any code in try catch blocks and see what errors you get.
Another idea is to print out logs what line is taken, then you will see at what line you get an error.
ive been through so many iterations i feel like im going insane, I legit Cant get this to work, i also cant itterate ColumnCount (or even ColumnName) Which MAKES ZERO SENSE because i an using the linq Direcetive.....


anyways, this is the latest, It returns
Subproject TT. Executing action CSharp OwnCode.id: fa84d638-9aa5-4894-aa37-b80022bbe117 Table does not contain column 150
So SOME HOW its trying to use the row return as a column?
I have NO CLUE why its doing this, ive read and read and im COMPLETELY stumped


100642

C#:
// get the unique ID to search for
var UID = project.Variables["UID"].Value;

// create a StringBuilder to store the log messages
var log = new StringBuilder();

// get the table to search in
var sourceGTable = project.GoogleSpreadsheets["Tabel1"];

// search for the row that contains the unique ID
// use a bool variable to keep track of whether the unique ID was found
bool found = false;

// define the row variable and set it to a default value of -1
int row = -1;

// loop through all rows in the table
for(int i=0; i < sourceGTable.RowCount; i++)
{
    // read a row from the table (it will be a cell array)
    var cells = sourceGTable.GetRow(i).ToArray();

    // loop through all cells in the row
    for (int j=0; j < cells.Length; j++)
    {
        // check the content of the text in the cell, if there is a match, set the row number
        if (cells[j].Contains(UID))
        {
            row = i;
            found = true;
            // add a log message
            log.AppendLine("Found unique ID in row " + row);
            // use break to exit the inner for loop
            break;
        }
    }

    // check if the unique ID was found
    if (found)
    {
        // use break to exit the outer for loop
        break;
    }
}

// if nothing is found, return "no"
if (row == -1)
{
    // add a log message
    log.AppendLine("Unique ID not found in table");
    // return the log messages
    return log.ToString();
}

// list of variables to check, with the corresponding column letter
var Dic = new Dictionary<string, string>()
{
    {"Variable21", "A"},
    {"UNIX", "B"},
    {"Date", "C"},
    {"Title", "D"},
    {"URL", "E"},
    {"Master", "F"},
    {"DBG", "G"},
    {"List", "H"},
    {"Offical", "I"},
    {"FB", "J"},
    {"Twiiter", "K"},
    {"IG", "L"},
    {"DB", "M"},
    {"Variable25", "N"},
    {"Variable24", "O"},
    {"Dir", "P"},
    {"Companies", "Q"},
    {"Distribute", "R"},
    {"Language", "S"},
    {"Rate", "T"},
    {"Aka", "U"},
};

// loop through all the variables in the dictionary
foreach (var kvp in Dic)
{
    // get the column letter for the current variable
    var columnLetter = kvp.Value;
    var variableName = kvp.Key;

    // read the first row of the table, which should contain the column names
    // exclude any empty columns in the row
    var columnNames = sourceGTable.GetRow(0).Where(c => !string.IsNullOrEmpty(c)).ToArray();

    // use the IndexOf method to find the column index for the given column letter
    var columnIndex = Array.IndexOf(columnNames, columnLetter);

    // if the column index is -1, the column was not found
    if (columnIndex == -1)
    {
        // add a log message
        log.AppendLine("Column " + columnLetter + " not found in table");
        continue;
    }

    // get the value of the variable
    var value = project.Variables[variableName].Value;

    // get the value in the cell for the current column and row
    // pass the column index as an integer
    var cellValue = sourceGTable.GetCell(row, columnIndex);

    // check if the cell value matches the variable value
    if (cellValue == value)
    {
        // add a log message
        log.AppendLine("Values match for variable " + variableName + " and column " + columnLetter);
        // the values match, skip to the next variable
        continue;
    }

    // if the values don't match, update the cell value
    // use the SetCell method to update the value in the cell
    // pass the row and column index as strings
    sourceGTable.SetCell(row, columnIndex, value);

    // add a log message
    log.AppendLine("Values don't match for variable " + variableName + " and column " + columnLetter);
    log.AppendLine("Updating cell with value " + value);
}

// return the log messages
return log.ToString();
 

PHaRTnONu

Client
Регистрация
01.10.2016
Сообщения
340
Благодарностей
48
Баллы
28
Ok ive TRACED & scaled back bit to see wtf is going on/wrong
apparently i can not call the google sheet cell data?
I can search it sure, but i have NO idea why i cant call the data in the cell's

If some one could explain what is wrong here
C#:
// define a dictionary to map the Zenno Poster variables to the columns in the Google Sheet
Dictionary<string, int> columnMap = new Dictionary<string, int>()
{
    {"Name", 4},
    {"Date", 3},
    {"Tag", 14},
    {"TagTT", 18},
    {"Tor", 8}
};

// get the unique ID to search for
var ttUID = project.Variables["ttUID"].Value;

// get the table to be updated
var googleTable = project.GoogleSpreadsheets["Table"];

// create a StringBuilder to store the log messages
StringBuilder logBuilder = new StringBuilder();

// look in each row in the table
lock(SyncObjects.TableSyncer)
{
    for(int x=0; x < googleTable.RowCount; x++)
    {
        // read a row from the table (it will be a cell array)
        var cells = googleTable.GetRow(x).ToArray();

        // check the content of the cell in the first column (ttUID), if there is a match, update the row
        if (cells[0].Trim() == ttUID.Trim())
        {
            // loop through the variables in the column map
            foreach(var variable in columnMap)
            {
                // get the Zenno Poster variable and the corresponding column in the Google Sheet
                var zennoVariable = variable.Key;
                var column = variable.Value;

                // get the value of the Zenno Poster variable
                var value = project.Variables[zennoVariable].Value;

                // split the existing values into an array (if they contain multiple values separated by commas)
                var existingValues = cells[column].Split(new string[] { "," }, StringSplitOptions.None);
               
                // add the new value from the Zenno Poster variable if it is not already present
                if (!existingValues.Contains(value))
                {
                    existingValues.Append(value);
                }
               
                // log the value of the Zenno Poster variable and the corresponding cell in the Google Sheet
                logBuilder.AppendLine($"{zennoVariable}: {value} (Google Sheet cell: {cells[column]})");
           
                // update the cell with the new array of values
                googleTable.SetCell(column, x, string.Join(",", existingValues)); // <-- change this to update the correct column in the Google Sheet
                }

            // exit the loop
            break;
        }
    }
}

// return the log
return logBuilder.ToString();
Log Results сказал(а):
Execution of C# code of Result:Name: TEST (Google Sheet cell: )
Date: Saterday (Google Sheet cell: )
Tag: Oarnge, Grey (Google Sheet cell: )
TagTT: Billy, Joe, purple, Blue (Google Sheet cell: )
Tor: Billy, Green, blue, purple, Red (Google Sheet cell: )
100674
100675
100676
Table сказал(а):
tt9999999Fridaygreen, Red, appleBilly, Joe, purple, Blue

I Dont know where im going wrong here.
Its defently strange im not even pulling the data, the sheet does find the row accurately but. yeah im at a real loss here


So if some one could point me in a solution for getting the CELL data
 

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