Skip to content
/ csv Public

Library for reading and writing CSV file/content in Dart.

Notifications You must be signed in to change notification settings

maiah/csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

csv

Library for reading and writing CSV file/content in Dart.

Sample usage

Reading CSV File

Add csv to your pubspec.yaml as a dependency. Import csv.dart and you can use parseCsvFile method to get the contents of a CSV file.

import 'package:csv/csv.dart';
import 'dart:io';

void main() {
  File csvFile = new File('./sample.csv');

  Future<List<List<String>>> f = parseCsvFile(csvFile);
  f.then((List<List<String>> csv) {
    for (List<String> row in csv) {
      for (String col in row) {
        print('Column: $col');
      }
    }
  });
}

Writing CSV File

Use writeCsvFile method to create a CSV file from List<List<String>> object.

import 'package:csv/csv.dart';
import 'dart:io';

void main() {
  File csvFile = new File('./sample_write.csv');

  List<List<String>> csvFileContent = new List<List<String>>();
  List<String> row1 = new List<String>();
  row1.add('Name');
  row1.add('Age');
  row1.add('Gender');
  row1.add('Position');
  row1.add('Color');

  List<String> row2 = new List<String>();
  row2.add('Maiah');
  row2.add('26');
  row2.add('M');
  row2.add('Up');
  row2.add('Green');

  List<String> row3 = new List<String>();
  row3.add('James');
  row3.add('23');
  row3.add('M');
  row3.add('Up');
  row3.add('Red');

  csvFileContent.add(row1);
  csvFileContent.add(row2);
  csvFileContent.add(row3);

  writeCsvFile(csvFile, csvFileContent);
}

About

Library for reading and writing CSV file/content in Dart.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages