Problem loading .ods

Hello good morning!

Im having trouble loading an .ods file into a workbook, im doing :

InputStream f = inFile.getInputStream()
   OdsLoadOptions options = new OdsLoadOptions(LoadFormat.ODS);
	Workbook book = new Workbook(f, options); 

and whenever i check cell content i get nothing:

sysout book.getWorksheets().get(0).getCells().get(0,0).getDisplayStringValue();

am i missing something? Is this not the right way to load?

goodFile.zip (2.8 KB)

Thank you!

@hexxo,

I am not sure if you got the file into streams fine. Anyways, I tested your scenario/case using the simplest lines of code with your ODS file using our latest version/fix (Aspose.Cells for Java v22.11) and it works absolutely fine. I can get the string value of the cell fine:
e.g.
Sample code:

byte [] data = Files.readAllBytes(Paths.get("f:\\files\\goodFile.ods"));
InputStream f = new ByteArrayInputStream(data);
OdsLoadOptions options = new OdsLoadOptions(LoadFormat.ODS);
Workbook book = new Workbook(f, options);

System.out.println(book.getWorksheets().get(0).getCells().get(0,0).getDisplayStringValue());

output:

nombre

Please try the above code (please correct the file path accordingly) and let us know if you still find the issue.

Hello, thank you for your help!

On my side it doesn’t work so it must be related to the InputStream f, wich i do .getInputStream() from a MultipartFile

Even using

byte[] data = Files.readAllBytes(Paths.get("C:\\Example\path\\goodFile.ods"));
InputStream f = new ByteArrayInputStream(data);

i get no result with DisplayString. i have v22.11 already.

After a while i figured out my problem.

After

InputStream f = inFile.getInputStream()

i was was doing

FileFormatInfo formatInfo = FileFormatUtil.detectFileFormat(f);
String formatExtension = FileFormatUtil.loadFormatToExtension(formatInfo.getLoadFormat());

and then loading the woorkbook. I dont know why but doing this before loading messes up the loading. if i do it directly without checking FormatInfo it works fine.

Any ideia why this happens?

Thank you

@hexxo,

Please update/fix your code as following:
e.g.
Sample code:

 byte [] data = Files.readAllBytes(Paths.get("f:\\files\\goodFile.ods"));
 InputStream f = new ByteArrayInputStream(data);
 FileFormatInfo formatInfo = FileFormatUtil.detectFileFormat(f);
 String formatExtension = FileFormatUtil.loadFormatToExtension(formatInfo.getLoadFormat());
 System.out.println(formatExtension);
 f.close();
 f = new ByteArrayInputStream(data);
 OdsLoadOptions options = new OdsLoadOptions(LoadFormat.ODS);
 Workbook book = new Workbook(f, options);
 System.out.println(book.getWorksheets().get(0).getCells().get(0,0).getDisplayStringValue()); 

Let us know if you still find any issue.