Calling row.get(-1) damages Worksheet

In certain cases, worksheets seemed to get damaged when saved through aspose.cells4java.
At least MS Excel complained about a damaged worksheet within the file when opening. After some time of debugging, I found the root of the problem and created a minimalistic testcase:

public static void main(String[] args) throws Exception
{
	Workbook wb = new Workbook();
	Cells c = wb.getWorksheets().get(0).getCells();

	// Works
	c.getRows().get(0).get(0).getValue();

	// Uncomment this line to obtain a damaged Workbook:
	// c.getRows().get(0).get(-1).getValue();

	wb.save("D:/temp/out.xlsx");
}

As soon as someone calls method “.get()” on a Row-object with a negative value, the saved worksheet is reported damage afterwards.
I testet this with Version 21.4 and 22.4 (the lastet version as of creating this post). Same outcome for both versions.

Can you confirm the issue?

@oklein,

I used the code segment:
e.g.
Sample code:

Workbook wb = new Workbook();
Cells c = wb.getWorksheets().get(0).getCells();

// Works
c.getRows().get(0).get(0).getValue();

// Uncomment this line to obtain a damaged Workbook:
c.getRows().get(0).get(-1).getValue();

wb.save("D:/temp/out.xlsx");

and the output file is opened fine into MS Excel 2007, 2016. I do not get any exception by MS Excel. By the way. the line of code:

c.getRows().get(0).get(-1).getValue();

is wrong or illogical. An instantiated (not null) cell’s index position can be set to 0 or greater than 0. Could you share your output Excel file and which MS Excel version you are using?

@Amjad_Sahi

true, gettting the value of column -1 doesnt make sense at all, but this is what our software ran in to/did. Hard to find out what caused the defective workbook afterwards.

This is the resulting file from my machine:
out.zip (6.5 KB)

This is the message my Excel 2016 (Home and Business) gives me when opening the attached file:
grafik.png (3.9 KB)
It says (roughly translated from german):

“We have detected a problem with some of the content in “out.xlsx”. Should we try to recover as much as possible? If you trust this files’ source, click ‘yes’.”

If i click “yes”, Excel gives me this output:
grafik.png (8.7 KB)

(repaired records in …sheet1.xmlpar)

Dont hesitate to ask if i can be of any assistance…

@oklein,

Thanks for the output file and screenshots.

Your provided output file was generated by some older version. I did used the sample (as I shared above) and generated the XLSX which is fine tuned. Please find attached the output file for your reference.
files1.zip (6.7 KB)

Please make sure you are using latest version of Aspose.Cells for Java v22.4.

@Amjad_Sahi
When testing the case against version 22.4, my classpath must have been messed up somehow :face_with_raised_eyebrow:
So I stand corrected: The testcase above creates an error using version 21.4 but works just fine in version 22.4 of aspose cells. I just verified it using clean workspaces.

Sorry for the inconveniences and thanks again for your fast and kind support (as always) !

@oklein,

Good to know that your issue is sorted out by using the latest version (as suggested). Feel free to write us back if you have further comments or questions, we will be happy to assist you soon.