471,319 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Accessing parents of linked cells in Excel without COMException

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
2 2334
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
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.

Similar topics

1 post views Thread by David Krmpotic | last post: by
2 posts views Thread by Job Lot | last post: by
4 posts views Thread by IMS.Rushikesh | last post: by
1 post views Thread by Mark | last post: by
7 posts views Thread by Alain \Mbuna\ | last post: by
5 posts views Thread by mrid via DotNetMonster.com | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.