- Регистрация
- 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
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
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);
}
}
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