You are here

private function FeedsExcelParser::getSheets in Feeds Excel 6

Retrieve all relevant sheets from dataset.

1 call to FeedsExcelParser::getSheets()
FeedsExcelParser::parse in ./ExcelParser.inc
Implementation of FeedsParser::parse().

File

./ExcelParser.inc, line 35

Class

FeedsExcelParser
Parses a given file as a Excel file.

Code

private function getSheets(&$data) {
  $sheet_config = $this->config['sheets'];
  $available_sheets = array_keys($data->sheets);
  $sheet_ids = array();
  if (strlen($sheet_config) < 1) {
    $sheet_ids = $available_sheets;
  }
  else {
    $sheet_expressions = explode(EXCELSHEET_SEP, $sheet_config);
    foreach ($sheet_expressions as $expr) {
      list($from, $to) = explode(EXCELSHEET_RANGE, $expr);

      // Numeric Range
      if (is_numeric($from) && (!$to || is_numeric($to))) {
        if (!$to) {
          $to = $from;
        }

        // Add matching sheets to sheet ids
        foreach ($available_sheets as $available_sheet) {
          if ($from <= $available_sheet && $available_sheet <= $to) {
            $sheet_ids[$available_sheet] = $available_sheet;
          }
        }
      }
      else {
        foreach ($data->boundsheets as $sheet_id => $boundsheet) {
          if ($boundsheet['name'] == $expr) {
            $sheet_ids[$sheet_id] = $sheet_id;
          }
        }
      }
    }
  }
  $sheets = array();

  // Run every sheet and populate it with its id, name and fixed cells
  foreach ($sheet_ids as $sheet_id) {
    $excel_sheet = $data->sheets[$sheet_id];
    $excel_sheet['boundsheet_offset'] = $data->boundsheets[$sheet_id]['offset'];
    $excel_sheet['name'] = $data->boundsheets[$sheet_id]['name'];
    $excel_sheet['id'] = $sheet_id;

    //$sheets[$sheet_id] = token_get_values('excel_sheet', $sheet);
    $excel_sheet['fixed_cells'] = $this
      ->getFixed($data->sheets[$sheet_id]);
    $sheets[$sheet_id] = $excel_sheet;
  }
  return $sheets;
}