I have a project where I have the following cells on the first worksheet:
// Create and populate the first sheet (Page One)
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('Page One');
$objPHPExcel->getActiveSheet()->setCellValue('B8', $city);
$objPHPExcel->getActiveSheet()->setCellValue('B9', $state);
$objPHPExcel->getActiveSheet()->setCellValue('B10', $zipCode);
$objPHPExcel->getActiveSheet()->setCellValue('B12', $SSN);
$objPHPExcel->getActiveSheet()->setCellValue('B13', $birthDate);
This appears to work fine .. and displays the data as expected. the issue is that when i use a formula to combine these fields on another worksheet, it only pulls the first one. The code looks like this:
// Create and populate Sheet 2 (Page Two)
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex(1);
$objPHPExcel->getActiveSheet()->setTitle("Page Two");
$objPHPExcel->getActiveSheet()->setCellValue('A5', "='Page One'!B8&\" \"&'Page One'!B9&\", \"&'Page One'!B10");
$objPHPExcel->getActiveSheet()->setCellValue('A6', "=\"SSN: \"&'Page One'!B12");
$objPHPExcel->getActiveSheet()->setCellValue('A7', "=\"DOB: \"&'Page One'!B13");
on page one the variables all work. on page two the SSN and DOB work .. but the first field (A5) does not show the "City, State ZIP" it shows just the City.
Also in Excel once it is exported, the data in the cell isnt complete:
='Page One'!B8&" "
Why is it failing to add the other 2 fields?
thanks in advance.
Silver Tiger
I have been tweaking and found a solution that works.. the combination of single and double quotes was tricky as the "text" i wanted to add required escaped double quotes, while worksheet elements took unescaped single quotes as follows:
$objPHPExcel->getActiveSheet()->setCellValue('A5', "=CONCATENATE('Page One'!B8,\", \",'Page One'!B9,\" \",'Page One'!B10)");
This solution worked for me just fine.