Free Support Forum - aspose.com

New Workbook with csv file results in java.lang.IndexOutOfBoundsException: millisecond

Hi,

we tried to load a csv file we received which resulted to a IndexOutOfBoundsException

for reproduce this issue you need just a empty file with test.csv and the following line:

20200430;2020-05-01 04:45:06.99953;

java.lang.IndexOutOfBoundsException: millisecond
at com.aspose.cells.DateTime.(Unknown Source)

a conversion from this timestamp would work
2020-05-01 04:44:37.38364
and is converted to
2020-05-01 04:44:37,384

with 999 it seems round up is not possible anymore and there is the IndexOutOfBoundException thrown

I would like to ask if it is possible to fix this issue either with an option (don’t care about wrong conversion) in TxtLoadOptions when create new Workbook
(as I only found an option to deactivate the whole dateTime conversion setConvertDateTimeData(false) which we would not want to use, because we would like to have a conversion)
or just convert it with a overflow to the right date, or in case of error just import it with string and warning, instead of an exception

we used the following TxtLoadOptions for new workbook

String separator = ";" // in this case
separatorChar = separator.charAt(0);
			loadOptions = new TxtLoadOptions(LoadFormat.CSV);
			loadOptions.setSeparator(separatorChar);
			loadOptions.setEncoding(Encoding.getEncoding(ConstData.ENCODING));
			loadOptions.setRegion(CountryCode.AUSTRIA);


 try
		{
			ByteArrayInputStream stream = new ByteArrayInputStream(Files.readAllBytes(path));

			workbook = new Workbook(stream, loadOptions);
		}
		catch (Exception e)
		{
			// exception is happening here  
		}

TIA
best regards,
Norbert

@rbi-sw-dev,

Thanks for the sample code segment and details.

After an initial test, I am able to reproduce the issue (found your exception) as you mentioned by using the following simplest sample code with the attached file. I also noticed by using setConvertDateTimeData(false), the issue is not occurred, then you do not want to use this option.
e.g
Sample code:

String path = "f:\\Files\\test1.csv";
        String separator = ";"; // in this case
            char separatorChar = separator.charAt(0);
                            TxtLoadOptions loadOptions = new TxtLoadOptions(LoadFormat.CSV);
                            loadOptions.setSeparator(separatorChar);
                            loadOptions.setRegion(CountryCode.AUSTRIA);

                            Workbook workbook = new Workbook(path, loadOptions);//exception

I have logged a ticket with an id “CELLSJAVA-43177” for your issue. We will check if we could devise some way around to cope with it. We will evaluate your issue soon.

Once we have an update on it, we will let you know.
files1.zip (186 Bytes)

1 Like

@rbi-sw-dev,

This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@rbi-sw-dev,

Please try our latest version/fix: Aspose.Cells for Java v20.4.5 (attached)

Your issue should be fixed in it as we tested your scenario with the attached (latest) fix.

Let us know your feedback.
aspose-cells-20.4.5-java.zip (7.1 MB)

1 Like

Thanks a lot for the fast solution :slight_smile: it works perfect fine now, i love the way how it was solved going to the next second

well done
thanks

@rbi-sw-dev,

Good to know that your issue is sorted out by the new fix/version. Feel free to contact us any time if you have further comments or questions, we will be happy to assist you soon.

1 Like

The issues you have found earlier (filed as CELLSJAVA-43177) have been fixed in Aspose.Cells for Java v20.5. This message was posted using Bugs notification tool by ahsaniqbalsidiqui