Not able to read merged cells in the worksheet using C#.net

  • Thread starter Thread starter Gani tpt
  • Start date Start date
G

Gani tpt

Guest
I am working with worksheet comparisons.

In my worksheet, some of the cells had been merged.

when reading every cell it's working fine. But, when the cells are merged then it is not reading the exact cell value.

It's showing some other value which is not available in the excel.

How to check or handle merged cells..?

see my complete source code



strRangeToCheck = "A10:JB10";

var r = XLWS1.Range[strRangeToCheck];

lastLine = Math.Max(
XLWS1.Range[strRangeToCheck].Rows.Count,
XLWS2.Range[strRangeToCheck].Rows.Count);

for (int row = r.Row; row < r.Row + lastLine; row++)
{
int lastCol = Math.Max(
XLWS1.Range[strRangeToCheck].Columns.Count,
XLWS2.Range[strRangeToCheck].Columns.Count);

for (int column = r.Column; column < r.Column + lastCol; column++)
{
string currRange = null;
string PrevRange = null;
currRange = XLWS1.Cells[row, column].Merged;
PrevRange = XLWS2.Cells[row, column].Merged;

string Currval = null;
string Prevval = null;
//int? value = new double?();

Currval = Convert.ToString(XLWS1.Cells[row, column].Value);
Prevval = Convert.ToString(XLWS2.Cells[row, column].Value);

// Check for if the object is null.
if ((Currval == null) || (Prevval == null))
{

}
else
{
if (Currval != Prevval)
{
((Excel.Range)XLWS1.Cells[row, column]).Interior.Color = 255;
((Excel.Range)XLWS2.Cells[row, column]).Interior.Color = 5296274;
}
}

}

}

Continue reading...
 
Back
Top