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

Free Support Forum - aspose.com

LeftToRightSort failing for aspose version 8.1.2

Hi Team

I’m trying to sort left to right by below code.

import com.aspose.cells.*;

public class Main {

	public static void main(String[] args) {
		Workbook workbook;
		try {
			workbook = new Workbook("C:\\Sample.ods");

			int weekTopRow = 0;
			boolean weekTopFlag = false;
			Worksheet worksheet = workbook.getWorksheets().get(0);

			Cells cells = worksheet.getCells();
			DataSorter sorter = workbook.getDataSorter();

			sorter.setOrder1(SortOrder.ASCENDING);
			sorter.setKey1(0);
			sorter.setOrder2(SortOrder.ASCENDING);
			sorter.setKey2(1);
			CellArea ca = new CellArea();
			ca.StartRow = 0;
			ca.StartColumn = 0;
			ca.EndRow = 6;
			ca.EndColumn = 11;
			sorter.setSortLeftToRight(true);
			sorter.sort(cells, ca);
			
			workbook.save("C:\\Result.ods");

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

getting below error

java.lang.NullPointerException
_ at com.aspose.cells.WorksheetCollection.ao(Unknown Source)_
_ at com.aspose.cells.WorksheetCollection.t(Unknown Source)_
_ at com.aspose.cells.aia.a(Unknown Source)_
_ at com.aspose.cells.ahm.b(Unknown Source)_
_ at com.aspose.cells.aja.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:32)_

Adding the Sample file and the aspose version. And I cant use the Latest version because the License is expired Sample.zip (12.5 KB)

And this happens only when setLeftToRight is true… for false it gets executed fine.

@aymarzapak,

Thanks for the template file and sampel code.

I have evaluated your issue using your sample code with template file with v17.9.x and it works fine. I am afraid, this might be a bug in the older version (v8.1.2) that you are using. We are very sorry but we cannot evaluate issues in older versions. Also, we cannot fix or include fix in older versions. The fixes and other enhancements are based on latest APIs set only. In short, there is no alternative but to upgrade to latest version of the APIs which works fine as I tested.

Just wanted to know if there was any mistake in my passing the order of Sorting or setting the key.

@aymarzapak,

I think your code is Ok.

public void save(String fileName)
throws Exception
  {
String str = k.d(fileName);
int i1 = FileFormatUtil.a(str, this.e);
save(fileName, FileFormatUtil.a(i1, getSaveOptions()));
  })));
  }

String str = k.d(fileName); It’s failing here when leftToRight sort is true. No way i can upgrade the version now

@aymarzapak,

As I told you that it might be a bug or some other limitation in the older version that you are using. There is no alternative or workaround (but to upgrade to latest APIs set) apparently that you could use to cope with it. Still I will check with the concerned developer from product team if something can be done in the Excel file or in code (using v8.1.2) to sort it out and if we have some way around, we will get back to you. The chances are least but I will still confirm with product team.

@aymarzapak,

We did evaluate your issue. I am afraid, we could not find any workaround or solution to make it work with older version. So, there is no other alternative or workaround for your issue but to upgrade to latest version of the product.