PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 4, 2022

[FIXED] How to make horizontal table phpexcel?

 October 04, 2022     phpexcel     No comments   

Issue

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

this is code for the table that i've done i want to change it to horizontal.

the table from the coding

the table that i desire want horizontal table


Solution

As you're using $n for the row number; make it the column instead, and store each data item in rows 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++;
}


Answered By - Mark Baker
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing