Ignore:
Timestamp:
May 4, 2011, 9:53:40 AM (12 years ago)
Author:
s.h.sikkema@…
Message:

Improved CSV export

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/dbnp/studycapturing/AssayService.groovy

    r1790 r1803  
    523523
    524524        outputStream << rowData.collect { row ->
    525           row.collect{ it ? "\"$it\"" : '""' }.join(',')
     525          row.collect{
     526
     527              // omit quotes in case of numeric values
     528              if (it instanceof Number) return it
     529
     530              def s = it.toString()
     531
     532              def addQuotes = false
     533
     534              // escape double quotes with double quotes if they exist and
     535              // enable surround with quotes
     536              if (s.contains('"')) {
     537                  addQuotes = true
     538                  s = s.replaceAll('"','""')
     539              } else {
     540                  // enable surround with quotes in case of comma's
     541                  if (s.contains(',') || s.contains('\n')) addQuotes = true
     542              }
     543
     544              addQuotes ? "\"$s\"" : s
     545
     546          }.join(',')
    526547        }.join('\n')
    527548
Note: See TracChangeset for help on using the changeset viewer.