0

I have this code :

$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);
        }
    }

What I want to do is to fill $linesMiddleHeader[] with the different values of $lineMiddleHeader.

But when I look in it, the array is completely empty and I can't figure why. Maybe that's just a stupid error I did, if so it's either very well hidden or me being dumb.

Anyway, if someone is able to help me that would be awesome considering myself being nuts.

2
  • When you ask a question about an error, ALWAYS post the error log. To enable error reporting to your php code, append error_reporting(E_ALL); ini_set('display_errors', '1'); at the top of your script, what does it return ? Commented Jun 3, 2016 at 12:26
  • There is no error, the array was just not filled. Commented Jun 3, 2016 at 12:44

1 Answer 1

2

Your array is not $linesMiddleHeader but it is $linesMiddleNumber.

Change to this :

 if(isset($linesMiddleNumber[$rowindex]) && $rowindex == $linesMiddleNumber[$rowindex]){
Sign up to request clarification or add additional context in comments.

2 Comments

Omg... I feel so ashamed... So sorry I asked for this... I need to sleep. Anyway thank you so much !
No problem..Happy coding and get some sleep :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.