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

Free Support Forum - aspose.com

Cells cannot be merged because cells in range have already been merged

I’m trying to merge a cell with previous merged cells but I couldn’t find a way to do so with aspose.

Could you help me finding a way to do this? Since I can merge already merged cells with a new one in excel, I assume it’s possible to do the same using aspose, right? (please, tell me it is!)

Here is my method to merge previous cells:

public void mergePreviousCellWithNext(final int n) throws SpreadsheetWriterException {
if (writeMode == COLMODE) {
throw new IllegalStateException(“mergeWithNext() method does not support execution in COLMODE”);
for (int i = 0; i < n; i++) {
mergeColumns(getCurrentColumn() - n - 1, getCurrentColumn() - 1);

* Merge columns into a single cell starting with col1 and ending with
* col2. Assumes current row
* @param col1
* the starting column for merging
* @param col2
* the starting column for merging
public void mergeColumns(final int col1, final int col2) throws SpreadsheetWriterException {
ws.getCells().merge(getCurrentRow(), col1, 1, col2 - col1 + 1);

Is there a way to change method mergePreviousCellWithNext to make it detect if the previous cell is merged, and then make this merged cell merge with current one?


Please see the document/article on how to detect the merged cells area in the worksheet for your requirements, the example in the document shows how to detect the merged cells ranges and then un-merge areas:

Thank you.