Search code examples
phpexcel-2007phpexcel

issue in setting cell value by row and column after merge in phpexcel


I want to merge 1st row A1 to H1 and input category 1 and merge I1 to P1 and input category 2 as values. I am trying with this below code and it is merging columns which is fine but it is not inputting second category value.

what is wrong here?

    $this->excel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, "NetApp Nominator's Contact Information");        
    $this->excel->setActiveSheetIndex(0)->mergeCells('A1:H1');

    $this->excel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "NetApp manoj");        
    $this->excel->setActiveSheetIndex(0)->mergeCells('I1:P1');

Am using phpexcel.


Solution

  • That's because column 1 is column B, and column B no longer exists in row 1, it's part of the group of cells that you've merged (A1:H1), and now only the top-leftmost cell of the merge group exists.... there's no column C or D or E or H any more in row 1.... the next column that exists in row 1 is column I.

    Merging cells makes all but the top-left cell of the merge group inaccessible; but doesn't make them non-existent

    Assuming that you're trying to store the second value in column I, then that's column number 8, so

    $this->excel->getActiveSheet()->setCellValueByColumnAndRow(8, 1, "NetApp manoj");