cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to read csv/excel file and get columns data

SOLVED
Highlighted
Not applicable

How to read csv/excel file and get columns data

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 !

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to read csv/excel file and get columns data

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

21 REPLIES 21

Re: How to read csv/excel file and get columns data

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

Not applicable
(in response to)

Re: How to read csv/excel file and get columns data

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

Re: How to read csv/excel file and get columns data

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

Re: How to read csv/excel file and get columns data

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

Re: How to read csv/excel file and get columns data

Column mappings are the columns that your CSV files have, for instance if you have column1,column2,column3 on your csv file, you should set columnMappings field equal to column1;column2;column3 ( the same names as fields on the datashape TFData )

Re: How to read csv/excel file and get columns data

Ok, I have done that, thank you.
How can I get the data list of each columns now, pleaase !

Re: How to read csv/excel file and get columns data

What does you mean?

The result it's an infotable, just iterate over it:

for each(row in result.rows) {

     var valueColumn1 = row.column1;

.,...

}

Re: How to read csv/excel file and get columns data

Thank you mr.Carles,

My columns in the csv file are:

  columnMappings: 'cell_easting,cell_northing',

When I run this:

for each(row in result.rows) {

    var valueColumn1 = row.cell_easting;

}

I don't get any result.

Re: How to read csv/excel file and get columns data

Well what result do you want to get, I mean where do you want to add the result?

For instance you can log the result:

logger.info("My Value"+row.cell_easting);

To see on the logs if you are reading correctly the value.s