Reverse page Flag of xlsx type docs

My code for reverse page flag is
private static Workbook setReversePageFlagWorkbook(Workbook wb, String sflg) throws Exception
{
int flg = Integer.parseInt(sflg);
// We need a new Workbook to save new order of worksheets and replace old one
Workbook wb2 = new Workbook();

// Variable ‘i’ is current index of the slides and ‘f’ is just used for while loop check
int i = 0, f = 1;

// A new Worksheet Array is required to save all worksheets of given workbook
Worksheet [] array = new Worksheet[wb.getWorksheets().getCount()];

// If given flg is 1
if (flg == 1)
{

// ‘f’ flag is used to keep check if index ‘i’ remains in limit of workbook size
while(f == 1)
{

if (i < wb.getWorksheets().getCount())
{
// Getting the worksheet at the given index
Worksheet worksheet = wb.getWorksheets().get(i);

array[i] = worksheet;
i++;
}
// If ‘i’ increases workbook size then stop loop
else
{
f = 0;
}
}

// Going through the length of the Worksheet Array
for (int h = 0 ; h < array.length ; h++)
{
// Appending new wb2 with the worksheets of Worksheet Array but in descending order
wb2.getWorksheets().add();
wb2.getWorksheets().get(h).copy(array[array.length - h - 1]);
}

return wb2;
}

// Return old Workbook if no flag is 0
return wb;

}

And i load the document by:
// For the xlsx type documents
LoadOptions loadOptions = new LoadOptions(FileFormatType.XLSX);

// Taking the input file stream from connection and forming Workbook Object with the specific load options
wb=new com.aspose.cells.Workbook(conn.getInputStream(), loadOptions);

But it is giving error on the line
wb2.getWorksheets().get(h).copy(array[array.length - h - 1]);

In short the error comes with xlsx type documents when adding its worksheet to a new workbook wb2 by the above command…
The xls type documents are working just fine.

Tell me where i am going wrong

Hi Hafsa,

Thanks for your posting and using Aspose.Cells.

Please download and try the latest version: Aspose.Cells
for Java v8.3.1.2
and see if it makes any difference.

If your problem still occurs, then please provide us some simple runnable sample program replicating this issue which we could run at our end and replicate this issue. We will look into it and if there is some bug, we will log it in our database so that it could be fixed at the earliest.

Please also attach your source Excel file(s) which you are using in your code. Thanks for your cooperation.