2017-04-19 45 views
0

$ periodOne = array('SNO','Appraisal','TOT','AVG','CLS TOT','CLS AVG','DIFF'));在PHPExcel我合併三個單元格,並foreach循環。合併後的結果下一個值不會打印

$rowID = 7; 
    foreach($periodOne as $rowArray) { 
     $columnID = 'A'; 
     foreach($rowArray as $columnValue) { 

      $this->setActiveSheetIndex(0)->mergeCells('B7:D7'); 
      $this->getActiveSheet()->setCellValue($columnID.$rowID,$columnValue); 



      $columnID++;  


     } 
     $rowID++; 
    } 
+1

除了這個事實,你歸併B7:D7多次;你也試圖獲得細胞C7和D7(因爲它們合併到B7而不再存在) –

+0

和解決方案 – neo

+0

我明白了......但它的小小巧,如果其他情況能幫助我。 – neo

回答

0
$periodOne=array(array('SNO','Appraisal','TOT','AVG','CLS TOT','CLS AVG','DIFF'));  

    $rowID = 7; 
    foreach($periodOne as $rowArray) { 
     $columnID = 'A'; 
     foreach($rowArray as $columnValue) { 
     if($columnID.$rowID == 'C7') 
     { 
      $columnID = 'E'; 



      $this->getActiveSheet()->setCellValue($columnID.$rowID,$columnValue); 



     } 
     else 
     { 

      $this->getActiveSheet()->setCellValue($columnID.$rowID,$columnValue); 


     }  
     $columnID++; 

     } 
     $rowID++; 
    }