Create excel sheet via dynamic html/javascript form

Topics: Developer Forum, Project Management Forum, User Forum
Feb 5, 2012 at 6:20 PM

I am sure the solution must be a simple one. I have a dynamic online form that I would like the data to be passed onto an excel sheet via PHPExcel. My form can add or delete lines. When I pass the info to the php script to create the excel sheet, I manage to view the lines when using the PHP "echo" function. However I cannot manage to get those lines onto the spreadsheet via PHPExcel. At best I get one line, which is always the last line, or I only get one numeric value in stead of the data itself.

 

Here is a snippet of my script:

$ids=explode(",",$_POST['count']);
for ($i=0;$i<count($ids);$i++)
{
 
 
 
 $level=$_POST['level'.$ids[$i]];
 $institution=$_POST['institution'.$ids[$i]];
 $board=$_POST['board'.$ids[$i]];
 $division=$_POST['division'.$ids[$i]];
 echo "level: ".$level;
 echo " institution: ".$institution;
 echo " board: ".$board;
 echo " division: ".$division;
 echo "<br/>";
 }

 

If I have for example three lines on the form, I can see 3 lines when it uses echo. How can I loop/iterate through the data and assign each line into an excel sheet using PHPExcel?

 

You kind assistance appreciated

Feb 5, 2012 at 7:42 PM

how about the same way you do with the echo statement. But in stead of echoing, you assign the values to cells in your spreadsheet. possibly using your iterator as an index for the row you want to put the data on.

Feb 6, 2012 at 8:01 AM

Can I please ask you to guide me here? I'm still learning PHP. How should I go about populating the cells? I want to start populating the sheet from line 10 in the spreadsheet.

$ids=explode(",",$_POST['count']);
for ($i=0;$i<count($ids);$i++)
{
 
 
 
 $level=$_POST['level'.$ids[$i]];
 $institution=$_POST['institution'.$ids[$i]];
 $board=$_POST['board'.$ids[$i]];
 $division=$_POST['division'.$ids[$i]];
 echo "level: ".$level;
 echo " institution: ".$institution;
 echo " board: ".$board;
 echo " division: ".$division;
 echo "<br/>";
 }

I am lookin for something like:

$objPHPExcel->getActiveSheet()->setCellValue('E'.$row??, $level);

How will I determine the row number and tell the script to loop through all the lines?

Kind assistance appreciated.

$objPHPExcel->getActiveSheet()->setCellValue('E'.$row??, $institution);

Feb 6, 2012 at 8:39 AM

how about using $i+10 as your row number? (like I suggested in the previous post). in code it could look like this:

$ids=explode(",",$_POST['count']);

for ($i=0;$i<count($ids);$i++){     
$level=$_POST['level'.$ids[$i]]; 
$institution=$_POST['institution'.$ids[$i]]; 
$row = $i + 10;
 
$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, $level); 
$objPHPExcel->getActiveSheet()->setCellValue('E'.$row, $institution); 
}


Feb 6, 2012 at 10:44 AM

Thank you s-o-o-o-o much for the pointer. It is working fine as expected. God bless!