Dart DocumentationCsvSheetCsvRow

CsvRow class

Currently CsvRow is only used as a type passed to the CsvSheet.forEachRow method.

CsvRow is a 1-based index of the cells contained in that row. Alternatively any headers that the CsvSheet contains my also be used to index the rows.

class CsvRow {
 List<String> row;
 
 HashMap _headers;
 bool hasHeaders = false;
 
 CsvRow([this._headers, this.row]) {
   if(_headers != null) hasHeaders = true;
 }
 
 /**
  * 1-Based index of the contents in this row. Alternatively you may also
  * use any headers that the [CsvSheet] contains to index the values.
  * 
  *     var value = row['name'];
  *     var value = row['1'];
  *  
  *  Throws a [RangeError] if the column header provided does not exist
  *  or the index value is outside of the valid indexes.
  */
 String operator [](index) {
   if(index is String) {
     var tmp = index;
     if(!hasHeaders) {
       throw new RangeError('$tmp is not a valid column header');
     }
     
     if(!_headers.containsKey(index)) 
       throw new RangeError('$tmp is not a valid column header');
     
     index = _headers[index];
   } else {
     index -= 1;
   }
   return row[index];
 }
 
 /**
  * Currently writing back to the CsvRow is not supported. This operation
  * throws an [UnsupportedError].
  */
 operator []=(index, value) {
   throw new UnsupportedError('Unable to assign a value to a cell.');
 }
 
 String toString() => row.toString();
 
}

Constructors

new CsvRow([HashMap _headers, List<String> row]) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
CsvRow([this._headers, this.row]) {
 if(_headers != null) hasHeaders = true;
}

Properties

bool hasHeaders #

bool hasHeaders = false

List<String> row #

List<String> row

Operators

String operator [](index) #

1-Based index of the contents in this row. Alternatively you may also use any headers that the CsvSheet contains to index the values.

var value = row['name'];
var value = row['1'];

Throws a RangeError if the column header provided does not exist or the index value is outside of the valid indexes.

String operator [](index) {
 if(index is String) {
   var tmp = index;
   if(!hasHeaders) {
     throw new RangeError('$tmp is not a valid column header');
   }
   
   if(!_headers.containsKey(index)) 
     throw new RangeError('$tmp is not a valid column header');
   
   index = _headers[index];
 } else {
   index -= 1;
 }
 return row[index];
}

dynamic operator []=(index, value) #

Currently writing back to the CsvRow is not supported. This operation throws an UnsupportedError.

operator []=(index, value) {
 throw new UnsupportedError('Unable to assign a value to a cell.');
}

Methods

String toString() #

Returns a string representation of this object.

docs inherited from Object
String toString() => row.toString();