We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Hard to get value of merged cells

I’ve found it’s hard to get the value of the merged cells when I picked not the first cell of merged range:

  1. Determine whether it is a merged cell
  2. Get the merged range of this cell
  3. Get the first cell of merged range by Sheet.Cells uses the first row and column of this merged range
  4. Get the value of first cell of merged range

Is there a right way to did it?


Yes, your workflow is ok. See the sample code segment for your reference.
Sample code:

//Get the cell
Aspose.Cells.Cell sCell = worksheet.Cells[1,2];

//If last cell is merged then calculate its last cell.
if (sCell.IsMerged)
          Range rng = sCell.GetMergedRange();

          int idxCol = sCell.Column + rng.ColumnCount;
          int idxRow = sCell.Row + rng.RowCount;

          string eCell = CellsHelper.CellIndexToName(idxRow, idxCol);

          Cell lastCell = ws.Cells[eCell];

//You may browse the cells in the range b/w the start cell and last cell easily 
//Your code goes here. 


Hope, this helps a bit.

Acturally, I hope there is a method to do this.


No, there is no single method available for the task, so you have devise your code accordingly (see my code segment for reference).

Feature request?


We cannot provide API for such a feature. I am afraid, we have to use such kind of solution (proposed above) even we provide an API for it. As a component, the data model is dynamic, so we cannot make any improvements for performance or for processing logic, so our API (if we provide) will give poor performance for the users. So we don’t think it is a meaningful or useful API for the users. But for end users, they know how their data is managed and when they need to check, so they may optimize the process using their own code and way, such as, sorting the merged areas or building map for those cells, …etc.

Thanks for your understanding!