By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

Accessing parents of linked cells in Excel without COMException

P: n/a
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
{
...
}
...

Jul 2 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ortega23

try to check whether srcCellRange.Precedents == null before calling its
Columns property

"ortega23" wrote:
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
{
...
}
...

Jul 3 '07 #2

P: n/a
Hi Sergey,

That was the first thing that I tried. But it does not work.
When I have a look at the cellRange in QuickWatch, some of the
properties throw ComExceptions while some others are available.
So I can't even make a null-check without COMException.

Name Value Type
------ ------ ------
Precedents 'cellRange.Precedents' threw an exception of type
'System.Runtime.InteropServices.COMException'
Microsoft.Office.Interop.Excel.Range
{System.Runtime.InteropServices.COMException}
Previous {System.__ComObject}
Microsoft.Office.Interop.Excel.Range {System.__ComObject}
Row 10 int

I am trying to figure out how to make this null check without
exception.
Do you have any suggestions?

Thanks.
ortega

Jul 3 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.