2017-08-23 42 views
1
$objPHPExcel->getActiveSheet()->setCellValue('A1', "No"); 
$objPHPExcel->getActiveSheet()->setCellValue('B1', "Name"); 
$objPHPExcel->getActiveSheet()->setCellValue('C1', "Age"); 
$objPHPExcel->getActiveSheet()->setCellValue('D1', "Job"); 
$styleArray = array('borders' => array('allborders' => array('style' => PHPExcel_Style_Border::BORDER_THICK,'color' => array('argb' => '808080'),),),); 
$objPHPExcel->getActiveSheet()->getStyle('A1:D1')->applyFromArray($styleArray); 

$sql="SELECT * FROM CUBA"; 
$query_c = mysqli_query($conn,$sql); 
$n=2; 
while($row_result=mysqli_fetch_assoc($query_c)){ 
         $objPHPExcel->getActiveSheet()->setCellValue('A'.$n,$row_result['id']); 
         $objPHPExcel->getActiveSheet()->setCellValue('B'.$n,$row_result['name']); 
         $objPHPExcel->getActiveSheet()->setCellValue('C'.$n,$row_result['age']); 
         $objPHPExcel->getActiveSheet()->setCellValue('D'.$n,$row_result['job']); 
       $n++; 
} 
    $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true); 
    $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true); 
    $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true); 
    $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true); 

這是我所做的表的代碼,我想將其更改爲水平。如何製作水平表phpexcel?

the table from the coding

當你使用$n的行數我的願望想 horizontal table

回答

0

表;使其列代替,並儲存在1-4行的每個數據項:

$n='B'; 
while($row_result=mysqli_fetch_assoc($query_c)){ 
    $objPHPExcel->getActiveSheet()->setCellValue($n.'1',$row_result['id']); 
    $objPHPExcel->getActiveSheet()->setCellValue($n.'2',$row_result['name']); 
    $objPHPExcel->getActiveSheet()->setCellValue($n.'3',$row_result['age']); 
    $objPHPExcel->getActiveSheet()->setCellValue($n.'4',$row_result['job']); 
    $n++; 
} 
+0

語法錯誤,意想不到的」 1.1' (T_DNUMBER) –

+0

然後加上引號 –

+0

行數它的工作謝謝... –