8.8.0 regression : Cells.copyRow()

A named range is created when copyRow method is used within a named range.
This behaviour appeared between 8.7.2 and 8.8.0 versions.

public static void main(String[] args) throws Exception {
Workbook workbook = new Workbook();

Cells cells = workbook.getWorksheets().get(0).getCells();
Range range = cells.createRange(0, 0, 1, 1);
range.setName(“R”);
printRanges(workbook);
cells.copyRow(cells, 0, 1);
printRanges(workbook);
}

private static void printRanges(Workbook workbook) {
NameCollection names = workbook.getWorksheets().getNames();
System.out.println("ranges: " + names.getCount());
@SuppressWarnings(“unchecked”)
Iterator iterator = names.iterator();
while (iterator.hasNext()) {
Name name = iterator.next();
System.out.println(name.getFullText());
}
}

(The purpose of this code is to automatically grow a vertical range by inserting rows in it, as can be done with Excel.)

Hi,


Thanks for providing us sample code and details.

After an initial test, I observed the issue as you mentioned by using the following sample code. I found an extra (new) named range is created when Cells.copyRow() method is used within a named range where it should not add/update the named range as per MS Excel’s behavior. The issue is reproducible with the latest versions e.g v8.8.0.x where as it works fine in older versions e.g v8.7.1 as you pointed out.
e.g
Sample code:

public static void main(String[] args) throws Exception
{

Workbook workbook = new Workbook();

Cells cells = workbook.getWorksheets().get(0).getCells();
Range range = cells.createRange(0, 0, 1, 1);
range.setName(“test1”);
printRanges(workbook);
cells.copyRow(cells, 0, 1);
printRanges(workbook);
workbook.save(“out1.xlsx”);
}

private static void printRanges(Workbook workbook) {
NameCollection names = workbook.getWorksheets().getNames();
System.out.println("ranges: " + names.getCount());
@SuppressWarnings(“unchecked”)
Iterator iterator = names.iterator();
while (iterator.hasNext()) {
Name name = iterator.next();
System.out.println(name.getFullText());
}
}

Output:
ranges: 1
test1
ranges: 2 //Not Ok, it should be 1
test1
Sheet1!test1 // invalid

I have logged a ticket with an id “CELLSJAVA-41839” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,

Thanks for using Aspose.Cells.

This is to inform you that we have fixed your issue CELLSJAVA-41839 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

Thanks for quick fix.

Here is a work-around … for whom may be concerned:

List namesBefore = new ArrayList<>();
sheets.getNames().forEach(new Consumer() {
@Override
public void accept(Name name) {
namesBefore.add(name.getFullText());
}
});

// ACTIONS WITH COPYROW //

NameCollection namesAfter = workbook.getWorksheets().getNames();
for (int i = namesAfter.getCount() - 1; i >= 0; i–) {
Name name = namesAfter.get(i);
if (!namesBefore.contains(name.getFullText())) {
namesAfter.removeAt(i);
}
}

Hi,

Thanks for sharing the workaround and using Aspose.Cells.

We are hopeful, your workaround will be helpful for other Aspose.Cells users. Besides, we will provide a fix for this issue in couple of days hopefully on Friday or Monday. Let us know if you encounter any other issue, we will be glad to look into it and help you further.

mshakeel.faiz:

we will provide a fix for this issue in couple of days


Is there a version I can use with this fixed ?

Hi,

Thanks for your posting and using Aspose.Cells.

Your issue is fixed in Aspose.Cells for Java v8.8.1 which is not released yet. However, Aspose.Cells for .NET 8.8.1 has already been released. Therefore Java version is also about to be released in next 2 or 3 days.

Meanwhile, please download and try the current latest version: Aspose.Cells for Java v8.8.0.3
and see if it makes any difference.

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


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.