Need help with phpexcel and exploaded data.

Topics: User Forum
Nov 2, 2010 at 7:15 PM

First of all I want to apologise for my bad English, and im fairly new to php coding so please have patience with me.

I have a website where customers can  choose 2 different values, depending on which certain column in excel will be populated. But with one radio button i want to send 2 values coz i want those 2 values from 1 button to go on separate cells in excel.

radio buttons  look like this:

<input type="radio" name="group1" value="Cheese,300" checked>Cheese<br>
<input type="radio" name="group1" value="Meat,500">Meat<br>

 

and in the file that is making the acctual excel file using phpexcel i used explode fuction like this

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

and when i wanted to insertit into certain cell i used next command

$objPHPExcel->getActiveSheet()->setCellValue('E45', $group1[0]['group1']);

$objPHPExcel->getActiveSheet()->setCellValue('A22', $group1[1]['group1']);

Problem is that when i open excel file .... in cell A22 i get C, and in cell E45 i get 3.

So im only getting first letter in those cells.

If anybody can offer some help id really appriciate it . Thank you.

Nov 2, 2010 at 7:22 PM

Hi,

 

change:

$objPHPExcel->getActiveSheet()->setCellValue('E45', $group1[0]['group1']);

$objPHPExcel->getActiveSheet()->setCellValue('A22', $group1[1]['group1']);

to

$objPHPExcel->getActiveSheet()->setCellValue('E45', $group1[0]);

$objPHPExcel->getActiveSheet()->setCellValue('A22', $group1[1]);

 

in php you can reference a string like an array, using indeces to reference an individual character. However, using a string as an index causes php to cast it to an integer. Apparantly casting the string "group1" to an integer value results in a 1, which results in the first character of the string, being either a C or a 3.

 

 

Mike

Nov 2, 2010 at 7:28 PM

Thank you so much. It worked perfectly.

I dont know why i havent tried that myself, i allways thought it was going to give me some error. :blushing

Thanks once again