Problems opening CSV

Hello, good morning!

Im currently tasked with receiving a inputStream from a CSV file and do some validations after, but right now i’m not able to load into into a Workbook.

This is the actual code at the moment:
InputStream f = inFile.getInputStream()

        TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
        options.setSeparator(';');
        
        Workbook book = new Workbook();
        book.getWorksheets().get(0).getCells().importCSV(f, options, 0, 0);

and then im checking the first cell just to see if the value is there
Cell firstCell = book.getWorksheets().get(0).getCells().get(0, 0);

What am i missing? It seems like it does not contain any of the csv info.
I have tried to load the file when building the workbook new Workbook(f, options) but the results are the same.

Thank you!

edit: currently using aspose-cells-19.12

@hexxo,

Thanks for the details.

Please zip and attach your sample CSV file that you are importing/loading via Aspose.Cells API. We will check your issue soon.

Thank you for your quick support!

here is a simple file example that was passed to me and i’m using
goodFile.zip (195 Bytes)

@hexxo,

Thanks for the CSV file.

I tried your scenario/case using our latest version/fix: Aspose.Cells for Java v22.11 (please try it), it works fine and as expected. I used the following sample code with your sample CSV file:
e.g
Sample code:

java.io.File file = new java.io.File("f:\\files\\goodFile.csv");
InputStream f =  new FileInputStream(file);

TxtLoadOptions options = new TxtLoadOptions(LoadFormat.CSV);
options.setSeparator(';');

Workbook book = new Workbook();
book.getWorksheets().get(0).getCells().importCSV(f, options, 0, 0);
Cell firstCell = book.getWorksheets().get(0).getCells().get(0, 0);
System.out.println(firstCell.getStringValue());

output:

nombre

Let us know if you still find the issue with newer version(s).

@Amjad_Sahi once again thank you for your reply!

It works perfect if i do it like that. The problem must be with the way the app gets the file.

If i use :
java.io.File file = new java.io.File(“f:\files\goodFile.csv”);
InputStream f = new FileInputStream(file);

it works as you say, but here i’m getting a MultipartFile inFile wich im doing a .getInputStream() like the example. In this case it shows a empty space when i print the StringValue.

Is there a workaround MultipartFiles?

Thank you!

@hexxo,

Aspose.Cells only works on valid CSV (single) file, so you have to implement to make multipart file to valid file and then use Aspose.Cells for processing. May be your multipart file is not obtained properly into streams so you have sort it out by yourselves.

Perfect! Thank you for all your help!

@hexxo,

You are welcome.