2 Replies Latest reply on Mar 10, 2016 9:48 AM by fguerra RSS
    fguerra Explorer

    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

      • Re: Read CSV starting on a different row
        carlesc Ninja

        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[i]);
        }
        fileRepository.SaveText({
            path: path,
            content: newContent.join("\n")
        });
        

         

        Hope it helps,

        Carles