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

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Read CSV starting on a different row

fguerra
5-Regular Member

Read CSV starting on a different row

Hello,

I'm using the Read CSV Snippet to read a csv file from my repository but this file has some lines at the beginning before starting with the information I want to show as infotable.

Is there any way to skip those likes without modifying the csv?

The csv file looks like this:

# Solar panel simulation inputs 2 of 2

# P9 - T_ambient, P27 - WB_Voc, P26 - Isc, P13 - WB_Panel_fill_factor

Name,P9,P27,P26,P13

1,20,6.1,0.00018,0.6

I want to show the infotable with the info starting on Name,P9…  but since the file probably will change from time to time I don’t want to change the format or the content.

Any help would be appreciated.

Thanks

Felix

2 REPLIES 2

Hi Felix,

You need to remove that rows on the file itself and rewrite it before parsing it through CSV extension, I do it that way:

var fileRepository = Things["file repository thing"];

var fileContent = fileRepository.LoadText({ path: "path to your file" });

var rows = fileContent.split("\n");

// -- Starting at 7 rows are the good ones.

var newContent = [];

for (var i=7;i<rows.length;i++) {

    newContent.push(rows);

}

fileRepository.SaveText({

    path: path,

    content: newContent.join("\n")

});

Hope it helps,

Carles

fguerra
5-Regular Member
(To:CarlesColl)

Hola Carles,

Thank you for your answer, great idea, I will test it.

Regards

Felix

Top Tags