Skip to content

Instantly share code, notes, and snippets.

@ivanionut
Forked from bardware/commons.cfm
Created November 14, 2017 10:52
Show Gist options
  • Save ivanionut/7b2ab35d58a0b61ce8e2c7c770da255a to your computer and use it in GitHub Desktop.
Save ivanionut/7b2ab35d58a0b61ce8e2c7c770da255a to your computer and use it in GitHub Desktop.
<!--- https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/package-summary.html --->
<cfset oCSV = createobject( "java", "org.apache.commons.csv.CSVFormat" )>
<cfset oParserObj = createobject( "java", "org.apache.commons.csv.CSVParser" )>
<cfdump var="#oParserObj#" expand="false">
<cfset oIOFile = createobject( "java", "java.io.File" ).init( expandpath( "./CLIENTIMPORT.csv" ) )>
<cfset oCharset = createobject( "java", "java.nio.charset.StandardCharsets" )>
<cfset oFormat = oCSV.EXCEL.withDelimiter( "|").withFirstRecordAsHeader().withQuote(javacast("char","")).withRecordSeparator("\r\n")>
<cfdump var="#oIOFile#" expand="false">
<cfdump var="#oCharset#">
<cfdump var="#oFormat#" expand="false">
<cfset oParser = oParserObj.parse(
oIOFile,
oCharset.UTF_8,
oFormat
)>
<cfdump var="#oParser#" expand="false" label="oParser">
<cfdump var="#oParser.getHeaderMap()#">
<cfset arrRecords = oParser.getRecords()>
<cfdump var="#arrRecords#">
<cfloop array="#arrRecords#" index="oRecord">
<cfdump var="#oRecord.toMap()#">
</cfloop>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment