Using CsvProcessor in Code - lgeorgieff/csv-processor GitHub Wiki

Description

After you have defined the XML configuration you can start writing your code.

  1. Define all required generic operations
  2. Register all defined and required generic operations
  3. instantiate a CSV.Job.Job object with the path to your XML configuration file
  4. You can use the results by calling job.Results (Note: the CSV is only processed when you invoke the Results property)

Define All Required Generic Operations

let makeUpperCase(line: Line): option<Line> =
    List.map(fun(cell: ICell) ->
        { Cell.Name = cell.Name; Cell.Value = cell.Value.ToUpper() } :> ICell) line
    |> Some

let maskSpace(document: Lines): Lines =
    List.map(fun(line: Line) ->
        List.map(fun(cell: ICell) ->
            { Cell.Name = cell.Name; Cell.Value = cell.Value.Replace(' ', '_') } :> ICell) line) document

Register All Required and Defined Generic Operations

GenericTask.RegisterOperation("upper-case-transform", makeUpperCase)
GenericTask.RegisterOperation("space-transform", maskSpace)

Instantiating a Csv.Job.Job

let job = new CSV.JobJob("config.xml")

Using All CSV.Job.Job Results

let results = job.Results

⚠️ **GitHub.com Fallback** ⚠️