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.
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).
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.
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.