$objPHPExcel->addNamedRange( new PHPExcel_NamedRange('PersonFN', $objPHPExcel->getActiveSheet(), 'B1') );
$objPHPExcel->addNamedRange( new PHPExcel_NamedRange('PersonLN', $objPHPExcel->getActiveSheet(), 'B2') );
Optionally, a fourth parameter can be passed defining the named range local (i.e. only usable on the current worksheet). Named ranges are global by default.
4.6.39. Redirect output to a client’s web browser
Sometimes, one really wants to output a file to a client’s browser, especially when creating spreadsheets on-the-fly. There are some easy steps that can be followed to do this:
Create your PHPExcel spreadsheet
Output HTTP headers for the type of document you wish to output
Use the PHPExcel_Writer_* of your choice, and save to “php://output”
PHPExcel_Writer_Excel2007 uses temporary storage when writing to php://output. By default, temporary files are stored in the script’s working directory. When there is no access, it falls back to the operating system’s temporary files location.
i This may not be safe for unauthorized viewing! Depending on the configuration of your operating system, temporary storage can be read by anyone using the same temporary storage folder. When confidentiality of your document is needed, it is recommended not to use php://output.
Example of a script redirecting an Excel 2007 file to the client's browser:
/* Here there will be some code where you create $objPHPExcel */
Make sure not to include any echo statements or output any other contents than the Excel file. There should be no whitespace before the opening <?php tag and at most one line break after the closing ?> tag (which can also be omitted to avoid problems).
Make sure that your script is saved without a BOM (Byte-order mark). (Because this counts as echoing output)
Same things apply to all included files
Failing to follow the above guidelines may result in corrupt Excel files arriving at the client browser, and/or that headers cannot be set by PHP (resulting in warning messages).