LeftTORightSort Error on Aspose Cells Version 8.1.2

Hi,

I’m using aspose Cells 8.6.1 in java

I’m trying to LeftToRight Sort it gives me Below Error. BuT if I change for Higher Version like 8.6.3 or the latest Version It works Fine. Just wanted to know in details that why this is not working in 8.6.1 version for some reason?

Exception in thread “main” java.lang.NullPointerException
at com.aspose.cells.WorksheetCollection.ao(Unknown Source)
at com.aspose.cells.WorksheetCollection.t(Unknown Source)
at com.aspose.cells.la.n(Unknown Source)
at com.aspose.cells.la.(Unknown Source)
at com.aspose.cells.qn.C(Unknown Source)
at com.aspose.cells.qn.a(Unknown Source)
at com.aspose.cells.qm.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at iteratew.Main.main(Main.java:41)

@aymarzapak

It might be that the older version has some bug. Please provide us your sample code and sample Excel file, we will look into this issue further and help you asap.

package iteratew;

import com.aspose.cells.Cell;
import com.aspose.cells.CellArea;
import com.aspose.cells.Cells;
import com.aspose.cells.DataSorter;

import com.aspose.cells.SortOrder;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class Main {

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

	Workbook workbook = new Workbook("C:\\Sample.xls");
	Worksheet worksheet = workbook.getWorksheets().get(0);
	Cells cells = worksheet.getCells();
	
	DataSorter sortertopCols = workbook.getDataSorter();
	
	sortertopCols.setSortLeftToRight(true);
	sortertopCols.addKey(1, SortOrder.ASCENDING);
	sortertopCols.addKey(2, SortOrder.ASCENDING);
	sortertopCols.addKey(3, SortOrder.ASCENDING);
	sortertopCols.addKey(4, SortOrder.ASCENDING);
	sortertopCols.addKey(5, SortOrder.ASCENDING);
	
	CellArea cellArea2 = CellArea.createCellArea("B2","I7");
	
	sortertopCols.sort(cells, cellArea2);
	worksheet.autoFitColumns();
	workbook.save("C:\\Excel\\sampleAfter.xlsx");
	System.out.println("done");
	
}

}

My Sample code. and have attached the sample File usedSample.zip (1.8 KB)

@aymarzapak

Please sort your Excel file manually via Microsoft Excel and save it and then provide it to me. I mean, I need sorted Excel file (i.e. your expected Excel file). Besides, I need the Sort dialog settings as shown in this screenshot.

Screenshot:
sc.png (80.9 KB)

sample.png (59.5 KB)

@aymarzapak

Thanks for your screenshot. We will look into this issue and help you asap.

@aymarzapak

We were able to confirm that your issue was occurring because of some bug in older version and 8.6.3 or higher versions are working fine. So, you will have to use the newer version because we do not fix the issues in older versions. We always fix the issue which are present in most recent version.

It means, if your older license allows you to use 8.6.3, then you can use it. But if your license does not allow you to use 8.6.3, then you will have to use the most recent version by purchasing new license.

Hi shakeel,

Just an update, I found that it tries to get a SaveOptions in save function and I’m not declaring anything. so it finds it as null . is the reason why that Null pointer Exception. So can you guide me for setting SaveOptions so that this works. its not because the leftToRight Sort the Exception is in Save Function of Workbook for the Save Options. I can update to the latest version, since it is a bit high level permissions, just trying if anything can work here … Can you help me with that Save Options…

@aymarzapak

SaveOptions is base class and it cannot be instantiated. For example, the following code is invalid

//You cannot create the instance of this class
SaveOptions so = new SaveOptions();

There are number of classes that are derived from SaveOptions. These are the followings.

  • DifSaveOptions
  • HtmlSaveOptions
  • ImageSaveOptions
  • OdsSaveOptions
  • OoxmlSaveOptions
  • PdfSaveOptions
  • SpreadsheetML2003SaveOptions
  • TxtSaveOptions
  • XlsbSaveOptions
  • XlsSaveOptions
  • XpsSaveOptions

For more information, please check the API references of Java (.NET is also useful).