Skip to content

CSV library for Actionscript ported from Apache Commons CSV

Notifications You must be signed in to change notification settings

lizardon/CSV4AS3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

CSV4AS3 is a CSV library for Actionscript that has been ported from Apache Commons CSV

Advantages of this library include:

  • Ability to parse incrementally without the need to read entire file into memory
  • Support for custom CSV format settings
  • Support for handling escapes and comments
  • Includes a CSV printer
  • Supports UTF8 compatible text formats

Getting Started - Parsing a CSV File

Step 1: Create and open a IDataInput object such as a FileStream

var file:File = new File("C:\\Users\\userdir\\test.csv");
var input:FileStream = new FileStream();
input.open(file, FileMode.READ);

Step 2: Create and Configure A CSVParser:

// in this case the CSV file has a header
var parser:CSVParser = new CSVParser(input, CSVFormat.buildDefaultWithHeader());
var headerMap:Object = parser.getHeaderMap(); 

Step 3: Iterate over the records

var record:CSVRecord;
while(parser.hasNext())
{
  record = parser.next();

  for (var columnName:String in headerMap)
  {
    trace(columnName + ": " + record.getValueByName(columnName));
  }
}

Alternatively parser.getRecords() will return an Array of CSVRecords of all the remaining rows in the file without needing to iterate.

Step 4: Close the input source

input.close();

About

CSV library for Actionscript ported from Apache Commons CSV

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published