ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get the value of a merged cell using c# (https://www.excelbanter.com/excel-programming/416074-how-get-value-merged-cell-using-c.html)

Issac

How to get the value of a merged cell using c#
 
Hi,
Is there a standard way to get the value of a merged cell using c#?

I tried both
1) target.Text
and
2) object[,] arr =
(object[,])target.get_Value(XlRangeValueDataType.xlRangeValu eDefault);
if (null != arr)
ret = Convert.ToString(arr[1, 1]);

If I used method 1), sometimes I got empty string back even though the
value is not an empty string.
If I used method 2), sometimes I got an exception even though the cell
has value.

Any thoughts?

Thanks.

Peter T

How to get the value of a merged cell using c#
 
try
target.MergeArea(1,1).Value

or .Text if you want a string of the value as formatted and displayed

Regards,
Peter T

"Issac" wrote in message
...
Hi,
Is there a standard way to get the value of a merged cell using c#?

I tried both
1) target.Text
and
2) object[,] arr =
(object[,])target.get_Value(XlRangeValueDataType.xlRangeValu eDefault);
if (null != arr)
ret = Convert.ToString(arr[1, 1]);

If I used method 1), sometimes I got empty string back even though the
value is not an empty string.
If I used method 2), sometimes I got an exception even though the cell
has value.

Any thoughts?

Thanks.





All times are GMT +1. The time now is 11:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com