private function Excel_XML::add2dRow in Views Excel Export 7
Add 2d array as row
Adds a single row to the document. If set to true, self::bConvertTypes checks the type of variable and returns the specific field settings for the cell.
Parameters
array $array One-dimensional array with row content:
int $max_inner_elements max subrows in row:
1 call to Excel_XML::add2dRow()
- Excel_XML::add3dArray in libs/
php-excel.class.php - Add an array to the document
File
- libs/
php-excel.class.php, line 146
Class
- Excel_XML
- Generating excel documents on-the-fly from PHP5
Code
private function add2dRow($array, $max_inner_elements) {
$cells = "";
$array = array_values($array);
for ($i = 0; $i < $max_inner_elements; $i++) {
$row = "<Row>\n";
$cells = '';
for ($j = 0; $j < count($array); $j++) {
if (is_array($array[$j])) {
$type = 'String';
if (isset($array[$j][$i]) && $this->bConvertTypes === true && is_numeric($array[$j][$i])) {
$type = 'Number';
}
if (isset($array[$j][$i]) && !isset($array[$j + 1][$i]) && $max_inner_elements - count($array[$j]) > 0) {
$cells .= "<Cell ss:MergeDown=\"" . ($max_inner_elements - count($array[$j])) . "\" ><Data ss:Type=\"{$type}\">" . $array[$j][$i] . "</Data></Cell>\n";
}
elseif (isset($array[$j][$i])) {
$cells .= "<Cell " . ($i > 0 ? 'ss:Index="' . ($j + 1) . '" ' : '') . " ><Data ss:Type=\"{$type}\">" . $array[$j][$i] . "</Data></Cell>\n";
}
}
elseif ($i == 0) {
$type = 'String';
if ($this->bConvertTypes === true && is_numeric($array[$j])) {
$type = 'Number';
}
$cells .= "<Cell ss:MergeDown=\"" . ($max_inner_elements - 1) . "\"><Data ss:Type=\"{$type}\">" . $array[$j] . "</Data></Cell>\n";
//else:
//$cells .= "<Cell><Data ss:Type=\"String\"> </Data></Cell>";
}
}
$row .= $cells;
$row .= "</Row>\n";
$this->lines[] = $row;
}
}