У меня есть биржевой тикер, который я построил как VSTO, который захватывает цену и затем вставляет ее в ячейку в определенных рабочих листах.Эти листы добавляются нажатием кнопки пользователя, который добавляет новый лист, форматирует его, а затем добавляет его имя на лист «accountList» (который отслеживает все эти специальные листы).
Проблема заключается в том, чточто он пишет только в самый новый лист, добавленный пользователем.Вот фрагмент того, что происходит во время цикла рабочего листа.
foreach (Excel.Worksheet currentWorksheet in Globals.ThisAddIn.Application.Worksheets)
{
tickerRange = currentWorksheet.Range["A6:A1000", Type.Missing]; //location of ticker symbols
//compare the current worksheet name to any of the names in the accountList
if (Array.IndexOf(accountList.ToArray(), currentWorksheet.Name) >= 0) {
//for every row in the specified range
foreach (Excel.Range row in tickerRange) //for every row inside the tickerRange variable
{
try
{
quoteCell = row.Offset[0, 5]; //location where market price will be inserted
string currentStock = row.Value2; //set ticker Symbol equal to the cell of the range element
if (string.IsNullOrEmpty(currentStock) || currentStock.Trim().Length > 4) //if there is nothing in the cell or the length is more than 4 characters, don't call the fetchPrice.
{
badValue = true;
}//end if
else if (Regex.IsMatch(currentStock, "[ ]|[0-9]")) //if the cell has whitespace or numbers, don't call fetchPrice. This would result in bad output
{
badValue = true;
}
else
{
currentStock = currentStock.ToUpper();
}
if (!badValue) //if the dictionary contains the ticker symbol, no need to call fetchPrice again this loop, just get the value out of dictionary
{
price = tickerDictionary[currentStock];
quoteCell.Value2 = price;
//volumeCell.Value2 = (stockObject.minuteVolume / stockObject.currentVolume)*100;
//break;
}
} //end try
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException rbe) //i forget why i had to catch this in the first place. but it came up once, and now it's caught. so there's that.
{
Console.WriteLine("Runtime Binder Exception caught");
}//end catch
catch (System.Runtime.InteropServices.COMException ce)
{
stopTicker();
}
} //end 'row' foreach
} //end 'sheet' foreach
Наблюдая за локальными переменными во время отладки, я вижу, что accountList заполнен правильной информацией, и циклы foreach попадают на другие мои листы, но quoteCell.Value2 = price
не обновляет цену на других листах.кроме моего самого нового.
Я что-то упускаю здесь глупо?