Skip to main content
1-Visitor
October 24, 2017
Solved

How to read csv/excel file and get columns data

  • October 24, 2017
  • 3 replies
  • 12804 views

Hello, I would like to read CSV file in the thingworx platform, I execute these java code into a service:

var params = {

    path: "TF.csv" /* STRING */,

    columnMappings: undefined /* STRING */,

    hasHeader: undefined /* BOOLEAN */,

    longitudeField: undefined /* NUMBER */,

    dateFormat: undefined /* STRING */,

    fileRepository: "SystemRepository",

    latitudeField: undefined /* NUMBER */,

    fieldDelimiter: "," /* STRING */,

    stringDelimiter: "," /* STRING */,

    dataShape: "TFData" /* DATASHAPENAME */

};

var result = Resources["CSVParserFunctions"].ReadCSVFile(params);

When I test this code lines, I got this error:

Wrapped java.lang.Exception: Unable To Convert From java.lang.String to NUMBER Cause: Unable To Convert From java.lang.String to NUMBER

Any help please !

Best answer by CarlesColl

Ta least you need columnMappings to be set ( separated by ";" ) and I don't think it's logic to set fieldDelimiter = stringDelimiter.

3 replies

1-Visitor
October 24, 2017

Ta least you need columnMappings to be set ( separated by ";" ) and I don't think it's logic to set fieldDelimiter = stringDelimiter.

1-Visitor
October 24, 2017

Thank you Mr.Carles,
I got this error now after deleting the stringDelimiter:

Wrapped java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 Cause: Index: 1, Size: 1

1-Visitor
October 24, 2017

Did you set column Mappings, do you have a String Delimiter( it's mandatory)

1-Visitor
October 24, 2017

How can I set a column Mappings ?
In my CSV file I have a delimiter and it's ','

1-Visitor
October 24, 2017

On moment I saw on one of your previous posts:

columnMappings: 'cell_easting,cell_northing'

should be:

columnMappings: 'cell_easting;cell_northing'

1-Visitor
October 24, 2017

Yes it is, I change that

var params = {

    path: "TF_Jun.csv" /* STRING */,

    columnMappings:'cell_easting;cell_northing',

    hasHeader: true /* BOOLEAN */,

    fileRepository: "SystemRepository",

    fieldDelimiter: "," /* STRING */,

    stringDelimiter: "\"" /* STRING */,

    dataShape: "TFUrbanizationData" /* DATASHAPENAME */

};

But the prob I got this error:

Wrapped java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 Cause: Index: 1, Size: 1

1-Visitor
October 24, 2017

If you aren't using latest csv file importer extension, add a new line on the bottom of the file.