[PHPExcel]

Topics: Developer Forum
Jan 22, 2012 at 7:53 AM

Hi guys, 

Im trying to read an existing excel file and write in it. Here is my code : 

<?php
include './Classes/PHPExcel.php'; include './Classes/PHPExcel/IOFactory.php'; include './Classes/PHPExcel/Writer/Excel2007.php'; include './Classes/PHPExcel/Reader/Excel2007.php';


$objet1 = new PHPExcel_Reader_Excel2007();
$excel1 = $objet1->load('BC_ENTREE_DATA.xlsx');


$sheet = $excel1->getSheetByName('ENTREE_BC_ETUDIANT');


$sheet -> setCellValueByColumnAndRow('1','7', 'test');





$save = new PHPExcel_Writer_Excel2007($excel1);

$save->save('BC_ENTREE_DATA.xlsx');


       
echo'Generation du fichier excel';                
?>

 

I have this error : Call to a member function setCellValueByColumnAndRow() on a non-object

I really don't know why.

Thanks for helping me.

Jan 23, 2012 at 2:38 PM

Try removing the quotes from the column and row values...

$sheet -> setCellValueByColumnAndRow(1, 7, 'test');

Coordinator
Jan 23, 2012 at 8:05 PM

First check that the sheet you're retrieving actually exists... if it doesn't exist, you'll be a NULL returned by the getSheetByName() method

Jan 23, 2012 at 9:51 PM

Actually I just test this code on another excel file and it does work...

On the first excel sheet there are comments from the author... I am  wondering if it is the reason why I cant write in it...

Thanks anyway guys

Coordinator
Jan 23, 2012 at 11:16 PM

Cell comments should be read by the Readers in the same way as any other cell content, so that shouldn't be a problem. Logging errors or checking the PHP logs can also help diagnose problems with files.