我有这段代码:
$previousParam = $table['rows'][0]['groupParam'];
$linesMiddleHeader=array();
$lineMiddleHeader=null;
if(array_key_exists("groupParam", $options)){
$lineNumber+=2;
$worksheet->setCellValue('A'.$lineNumber, $previousParam);
$worksheet->getStyle('A'.$lineNumber)->applyFromArray($borderStyle);
}
foreach ($table['rows'] as $rowindex => $row) {
$nbColumn=count($row['cells']);
// if(array_key_exists ("groupParam", $options)){
// $this->getLogger()->debug(":".$row['groupParam']);
// }
if($previousParam!=$row['groupParam']){
$lineNumber+=3;
$lineMiddleHeader=$lineNumber;
$worksheet->setCellValue('A'.$lineMiddleHeader, $row['groupParam']);
$worksheet->getStyle('A'.$lineNumber)->applyFromArray($borderStyle);
}
$linesMiddleNumber[$rowindex]=$lineMiddleHeader;
$previousParam = $row['groupParam'];
foreach ($row['cells'] as $column => $cell) {
// header
if ($rowindex == 0) {
$title = $table['headers'][$column];
$this->setCellValue($worksheet, $column, $previousLineNumber + 1, $title);
$headRow = $previousLineNumber + 1;
if(strcmp($title['title_code'], "Prix")==0){
$colPrice = PHPExcel_Cell::stringFromColumnIndex($column);
}
}
// var_dump($linesMiddleHeader);
if(isset($linesMiddleHeader[$rowindex]) && $rowindex == $linesMiddleHeader[$rowindex]){
$title = $table['headers'][$column];
$this->setCellValue($worksheet, $column, $linesMiddleHeader[$rowindex]-1, $title);
}
// cellule
if ($row['level'] == 0) {
if ($column == 0) {
$lineNumber++;
}
$columnCell=$column;
$this->setCellValue($worksheet, $columnCell, $lineNumber + $previousLineNumber, $cell);
}
$worksheet->getColumnDimensionByColumn($column)->setAutoSize(true);
}
}
我想要做的是使用$linesMiddleHeader[]
的不同值填充$lineMiddleHeader
。
但是当我查看它时,阵列完全是空的,我无法理解为什么。也许这只是我做过的一个愚蠢的错误,如果是这样,它要么被隐藏得很好,要么我是愚蠢的。
无论如何,如果有人能够帮助我,那么考虑到自己是坚果就会很棒。
答案 0 :(得分:2)
你的数组不是$ linesMiddleHeader,而是$ linesMiddleNumber。
更改为:
if(isset($linesMiddleNumber[$rowindex]) && $rowindex == $linesMiddleNumber[$rowindex]){