Hi,
I am trying to obtain the column number of the parent of a cell, if
the cell is a linked cell (i.e. its value depends on another cells
value).
I try to read "Precedents"(parent cells) of a "Range"(selection of a
single cell in this case) for each cell in my table to access parents
of the linked cells.
When a cell is not a linked one, I am geting a COMException. Therefore
I use a try-catch block. But this block reduces the speed of the
program dramatically.
I need to process 100x10000 cells, and without this block (just do not
do anything for linked cells) it is almost 2.5x faster.
For linked cells, I do not have any heavy work, I just add column
numbers to a list.
Could you suggest a better way to access the parent cells or avoid the
COMException?
Thanks.
ortega
The code looks like the this:
...
Microsoft.Office.Interop.Excel.Range cellRange =
worksheet.get_Range(x, y);
int parentCellColumn = -1;
try
{
if (srcCellRange.Precedents.Count 0)
{
// Max parent count is 1 in the table.
parentCellColumn = srcCellRange.Precedents.Column;
}
}
catch (System.Runtime.InteropServices.COMException e)
{
}
finally
{
...
}
...