MF

Hello, i am trying to read from a .csv file which is in a defined location and thereafter manipulate the data.

I used to convert the .csv file manually to a .xls file and then import the.xls file and use it with the partial code below, however the new requirement is to read the .csv file directly.

Can anybody assist with the correct methods to read a .csv file and iterate through the lines.

Thanks

Michael

<=============>

 

var ImportFile = getpathandfile();

    if(ImportFile!=null)

    {

        var Excelapp = Context.getExcelReader(ImportFile.getData());

        var sheets = Excelapp.getSheets();

        var currentSheet = sheets[0];

        //var sheetname = currentSheet.getName();

        var dataRows = currentSheet.getRows ( );

        for(var m=0;m<dataRows.length;m++)

        {

            var data = new classData();

            data.vAppName = dataRows[m].getCellAt(0).getCellValue ( );

            data.vOS = dataRows[m].getCellAt(1).getCellValue ( );

            data.vHardwareVendor = dataRows[m].getCellAt(2).getCellValue ( );

            dataItems.push(data);

        }

by Tricarico Romain
Posted on Wed, 09/23/2015 - 18:01

Hi Michael,

To read a CSV file, you have to open it and read it line by line :

Example, here I get all lines in an array :

var arrayLines = new Array();
var Files = Dialogs.getFilePath("",  "*.csv", "I:\\BPMap\\1_clients\\CNP\\Organigramme", "Get SAP extraction Excel file", 0);  //Open a browser on the client side
    if(Files != null){
        var file = Files[0];
        var data = file.getData();
        var fstream = new java.io.ByteArrayInputStream(data);
        var inputstream = java.io.DataInputStream(fstream);
        var bufferReader = java.io.BufferedReader(new  java.io.InputStreamReader(inputstream));
        
        var strLine = "";
        while((strLine = bufferReader.readLine()) != null){
            arrayLines.push(strLine);
        }
    }

Hope that helps.

 

Best Regards

0
by Michael Fouche Author
Posted on Fri, 09/25/2015 - 11:10

In reply to by BPMap

Hello Tricarico, i thought there should be functionality like that. This made me realize I should rather look in the java api than in the minimalistic aris api to find functionality. Thanks for giving such a clear example, it works perfectly! :)

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks

Leaderboard

|
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock