Can anyone provide or point me in the direction of code or functionality that supports the parsing of data provided in a CSV file?  For example, I have a form where the user can upload a single CSV attachment consisting of a header row then a data row(s).  I need to be able to parse the CSV and extract data from certain columns/rows to do further processing.

Currently I am calling a Dynamic Data service and have worked out how to get the File Attachment but as a byte array.  Ideally would like to use a CSV Parser of some type that better handles the skipping of a line, data matching, etc.

Many thanks in advance for any assistance!

    CommentAdd your comment...

    1 answer


      In groovy you could do something like this:


      import java.io.StringReader
      import com.avoka.fc.core.util.CsvReader
      // presumably your data will come from a parameter instead of a file like I've done below
      def fileContent = new File('names.csv').getText()
      def csvReader = new CsvReader(new StringReader(fileContent))
      // do something with headers
      def headers = csvReader.readHeaders()
      def headerRecord = csvReader.getRawRecord()
      while (csvReader.readRecord()) {
        def firstname = csvReader.get(0) 
        def lastname = csvReader.get(1) 
        println "firstname: $firstname, lastname $lastname"
        CommentAdd your comment...