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

Free Support Forum - aspose.com

Set value to merged cells

Hi,

This post is related to
Shape objects and cells with data validation issues

When using Cells 7.0.2, we noticed that some merged cells get either unmerged or the merge got extended to the right. Unfortunately, we can’t replicate this issue with a simple file, nor were we able to find a rule to these changes. Basically, we got different results for the same input data on different runs.

We set the value in the merged cell by calling setValue for the cell at the top-left position. For example, if we had the merged cells B2:C4, I would set the value on the B2 cell.
Is this the correct way to do it?

Regards,
Sorin.

Hi,

You can access all the cells which are merged together by using the following pseudo code

Java.


if(cell.isMerged()==true)
{
//Access all the cells which are merged by calling
Range rng = cell.getMergedRange();

//Then access all the cells using range iterator;
rng.iterator();

}

The following code will explain you who to use range.iterator to access all the cells falling inside the range.

Java
Range rng = cell.getMergedRange();;

Iterator allCells = rng.iterator();

while(allCells.hasNext())
{
Cell nextCell = allCells.next();

//Print cell value
System.out.println(nextCell.getStringValue());
}

Hi,


We are afraid we need your template file and code to reproduce the issue. At least please give us your generated Excel files with different results (for merged areas etc.) first, so we can check whether we can get some clues from them.


Thank you.

Hi,

I managed to replicate the issue with a simple sample.
Book1.xls is the template file, output-7.0.2.xls is the output we get. It also has the issues highlighted.

Regards,
Sorin.

Hi,


After an initial test, I can find the issue as you have mentioned by using your sample code and template Excel file. I have logged a ticket for it with an id: CELLSJAVA-40010. We will look into it soon.

Thank you.

Hi,


Please try the new fixed version: v7.0.2.3 (attached). We have fixed the issues.<o:p></o:p>

Also, please use removeAt(int/String) method of WorksheetCollection, e.g

Change your line of code to:

// Remove the template sheet from the file

wss.removeAt(srcWs.getName());

Thank you.

Hi,

After I upgraded to the attached version of Cells, we no longer have the merging issues.

Thank you,
Sorin.

The issues you have found earlier (filed as CELLSJAVA-xxxxx) have been fixed in this update.