PHPEXCEL Writing in a cell without deleting the current value.

Topics: Developer Forum, Project Management Forum, User Forum
Jun 10, 2015 at 4:47 PM
Writing in a cell without deleting the current value. Example: A1 = Andres.
I need to add that cell A1 Suarez and it is = Andres Suarez.

How to doit with phpexcel

Thank you.
Coordinator
Jun 10, 2015 at 5:01 PM
Using basic PHP concatenation
$objPHPExcel->getActiveSheet()->setCellValue(
    'A1',
    $objPHPExcel->getActiveSheet()->getCell('A1')->getValue() . ' Suarez'
);
Jun 10, 2015 at 6:04 PM
Thanks 4 your anwser. (Sorry I'm very new in php and programming, and english) The system shows me this error:

Undefined variable: objPHPExcel
Fatal error: Call to a member function getActiveSheet() on a non-object.
Thanks.

This is my code.

require_once('../../../prod/third/phpexcel/PHPExcel.php');
require_once('../../../prod/third/phpexcel/PHPExcel/IOFactory.php');

//load Excel template file
$objTpl = PHPExcel_IOFactory::load("../../../app/MRE/doc/MRE.xlsx");
$objTpl->setActiveSheetIndex(0); //set first sheet as active

$objTpl->getActiveSheet()->setCellValue('A1', date('Y-m-d')); //set C1 to current date

//your code.
$objPHPExcel->getActiveSheet()->setCellValue(
'B1',
$objPHPExcel->getActiveSheet()->getCell('B1')->getValue() . ' Suarez'
);

//prepare download
$filename=mt_rand(1,100000).'.xls'; //just some random filename
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'.$filename.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objTpl, 'Excel5'); //downloadable file is in Excel 2003 format (.xls)
$objWriter->save('php://output'); //send it to user, of course you can save it to disk also!

exit; //done.. exiting!
Jun 10, 2015 at 6:36 PM
Hi, I used your code, but i change to this, and function.

$objTpl->getActiveSheet()->setCellValue('D3', $objTpl->getActiveSheet()->getCell('D3')->getValue() . "n\hola");

But now, I need that hola, apears like this:

dato1
hola

But it show me like this
dato1 hola.

Im using n\ but it dont make the jump.

thks