The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

RowIter

  $tr= RapidApp::Spreadsheet::ExcelTableReader(...);
  $i= $tr->iter;
  
  while (my $vals= $i->nextRowArray) {
    ...
  }
  $i->rewind;
  while (my $vals= $i->nextRowHash) {
    ...
  }

This class is an iterator that walks down the rows of an excel file. It is intended to be created by ExcelTableReader. It access the spreadsheet object of the parent for all its data, and extracts values using "->cell_text(y,x)", which has an interface of returning an empty string for undefined table cells.

ExcelTableReader

  $fields= [ 'foo', 'bar', 'baz' ];
  $colHdr= [ 'Foo', 'Bar And Stuff', 'Baz' ];
  $tr= RapidApp::Spreadsheet::ExcelTableReader(
    wsheet     => $ws,
    fields     => $fields,
    fieldLabels => $colHdr,
    headerCol  => 0
  );
  
  #optional
  $tr->findHeader or die "Not a valid Excel file";
  
  for ($i= $tr->itr; $row= $i->nextRowHash; ) {
    print Dumper(%$row);
  }
  
  $allRows_2dArray= $tr->rowsAsArray;
  $allRows_hashes= $tr->rowsAsHash;

ExcelTableReader simply takes a list of columns and looks for a row containing them in the Excel file. It then lets you iterate through the document pulling those columns into either a hash or an array. There are separate "fields" and "fieldLabels" properties in order to let you search for one string in the Excel file and associate it with a different name in the returned hash.

wsheet

wsheet is the worksheet object returned from Spreadsheet::PArseExcel. All values returned by TableReader come from reading cells in the worksheet.

fields

Fields specifies the official name of the data being extracted form a column. This name will be used as keys when returning row data as a hash. If you are only using array methods and specify the header row, this is ignored.

fieldLabels =head2 colHeaders

FieldLabels specifies the names to look for in the header row. If fieldLabels is not specified, it will default to the same as the name of the field.

headerCol

Required. Specifies the 0-based column in the excel file to search for the leftmost header, if a search is required. Else, it simply is the Y coordinate of the first header cell.

headerRow

Optional. Specifies the 0-based row in the excel file to search for the leftmost header. If not specified, the TableReader will search the worksheet form top to bottom looking for a row that matches the fieldLabels.

If specified directly, no search will be performed, and the header is assumed to exist at this row. (no check is performed either). It is possible to specify -1 if the data begins on row 0.

findHeader

Searches the excel worksheet top to bottom looking for the header row. Returns a row index (0-based, always true) if found, and undef of not found. Only the "headerCol" column is searched for the leftmost column (i.e. it never searches sideways), and all columns must match. There is no "near match which generates a warning" feature, though that might be nice.

iter

Creates an iterator object to help iterate through the rows.

rowsAsHash

  $tr= RapidApp::Spreadsheet::ExcelTableReader(
    wsheet     => $ws,
    fields     => $fields,
    headerCol  => 0
  );
  $allRows_hashes= $tr->rowsAsHash;

Returns all the rows of the Excel file in an array, each represented as an array of values in column order.

rowsAsHash

  $tr= RapidApp::Spreadsheet::ExcelTableReader(
    wsheet     => $ws,
    fields     => $fields,
    headerCol  => 0
  );
  $allRows_hashes= $tr->rowsAsHash;

Returns all the rows of the Excel file in an array, each represented as a hash of fieldname to value.