You are here

function _phpexcel_set_headers in PHPExcel 7

Same name and namespace in other branches
  1. 8.3 phpexcel.inc \_phpexcel_set_headers()
  2. 6.2 phpexcel.api.inc \_phpexcel_set_headers()
  3. 6 phpexcel.api.inc \_phpexcel_set_headers()
  4. 7.3 phpexcel.inc \_phpexcel_set_headers()
  5. 7.2 phpexcel.inc \_phpexcel_set_headers()

Sets the Excel file headers.

See also

phpexcel_export()

1 call to _phpexcel_set_headers()
phpexcel_export in ./phpexcel.api.inc
Simple API function which will generate an XLS file and save it in $path.

File

./phpexcel.api.inc, line 159
Defines the phpexcel api functions that other modules can use.

Code

function _phpexcel_set_headers(&$xls, &$headers, $options) {
  if (!is_array(reset(array_values($headers)))) {
    $headers = array(
      $headers,
    );
  }
  phpexcel_invoke('export', 'headers', $headers, $xls, $options);
  $sheet_id = 0;
  foreach ($headers as $sheet_name => $sheet_headers) {
    $xls
      ->createSheet($sheet_id);
    phpexcel_invoke('export', 'new sheet', $sheet_id, $xls, $options);
    $sheet = $xls
      ->setActiveSheetIndex($sheet_id);
    if (!is_numeric($sheet_name)) {
      $sheet
        ->setTitle($sheet_name);
    }
    else {
      $sheet
        ->setTitle("Worksheet {$sheet_id}");
    }
    for ($i = 0, $len = count($sheet_headers); $i < $len; $i++) {
      $value = trim($sheet_headers[$i]);
      phpexcel_invoke('export', 'pre cell', $value, $sheet, $options, $i, 1);
      $sheet
        ->setCellValueByColumnAndRow($i, 1, $value);
      phpexcel_invoke('export', 'post cell', $value, $sheet, $options, $i, 1);
    }
    $sheet_id++;
  }
}