function _phpexcel_set_columns in PHPExcel 6.2
Same name and namespace in other branches
- 8.3 phpexcel.inc \_phpexcel_set_columns()
- 6 phpexcel.api.inc \_phpexcel_set_columns()
- 7.3 phpexcel.inc \_phpexcel_set_columns()
- 7 phpexcel.api.inc \_phpexcel_set_columns()
- 7.2 phpexcel.inc \_phpexcel_set_columns()
Adds the data to the Excel file.
See also
1 call to _phpexcel_set_columns()
- 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 217 - Defines the phpexcel api functions that other modules can use.
Code
function _phpexcel_set_columns(&$xls, &$data, $cols, $options) {
$data = array_values($data);
if (!is_array($data[0][0])) {
$data = array(
$data,
);
}
phpexcel_invoke('export', 'data', $data, $xls, $options);
foreach ($data as $sheet_id => $sheet_data) {
$sheet = $xls
->setActiveSheetIndex($sheet_id);
for ($i = 0, $len = count($sheet_data); $i < $len; $i++) {
for ($j = 0; $j < $cols; $j++) {
$value = isset($sheet_data[$i][$j]) ? $sheet_data[$i][$j] : '';
// We must offset the row count (by 2, because PHPExcel starts the count at 1), because the first row is used by the headers
phpexcel_invoke('export', 'pre cell', $value, $sheet, $options, $j, $i + 2);
$sheet
->setCellValueByColumnAndRow($j, $i + 2, $value);
phpexcel_invoke('export', 'post cell', $value, $sheet, $options, $j, $i + 2);
}
}
}
}