Skip to content
This repository was archived by the owner on Aug 19, 2023. It is now read-only.
This repository was archived by the owner on Aug 19, 2023. It is now read-only.

Add toCSV method #13

@johnnyfreeman

Description

@johnnyfreeman

A coworker of mine needed a CSV to be filtered this week and it involved something a little more complex than what Excel offers out of the box. So my thought was to use Coseva to filter the list and then write that back to a CSV format after parsing.

Here was the quick & dirty method I used to accomplish the task:

/**
 * Write the parsed rows to a new CSV file.
 *
 * @return object \Coseva\CSV instance
 */
public function toCSV($filename)
{
    if (!isset($this->_rows)) $this->parse();

    $file = new SplFileObject($filename, 'w');

    foreach ($this->_rows as $row) {
        $file->fputcsv($row);
    }

    return $this;
}

Now I just need to make this a little more flexible...

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions