Reader/Writer Not Working

Topics: Developer Forum
Jun 4, 2012 at 4:16 AM
Edited Jun 4, 2012 at 4:19 AM

I'm working on a PHP script that reads in an excel template file, modifies is, then writes it to a temporary directory for pickup by a javascript function.  For some reason, every type of read attempt listed in the PHPExcel Developer Manual causes a 500 (Internal Server Error).  My code is as follows:


/** PHPExcel */
include 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

function create_excel_file($report_row_IDs) {
	// Create PHPExcel object from template
	$objReader = PHPExcel_IOFactory::createReader("Excel2007");
	$objPHPExcel = $objReader->load("../templates/Export Template.xlsx");

... Code to modify the file ...

	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
	$objWriter->save('../temp-export-files/Report' . $filePostfix . '.xlsx');

As I said, I've tried all readers (and writers) mentioned in the develop manual, but nothing seems to work for me.  At the moment, I'm simply testing on my local machine using MAMP.  Also worth noting is that I have been able to create a new excel file using PHPExcel, add to it, and save it to the temporary directory seen in the code above without issue.  Thanks in advance for any advice.

Jun 4, 2012 at 10:47 AM
Edited Jun 4, 2012 at 10:48 AM

In what way "doesn't work"?

Is any file being saved?

Is anything being written to the output file? to PHP or Webserver error logs? or even any PHP errors being written to the generated file?

Jun 4, 2012 at 12:50 PM

I'm calling the create_excel_file(...) function using JQuery.  When I click the button that makes the call, it thinks for a minute, then gives a 500 (Internal Server Error) message in my browser.  The file is never picked up, altered, or written.  I placed echo statements at the beginning of the code, and the line it's failing to process is 


$objPHPExcel = $objReader->load("../templates/Export Template.xlsx");


In addition, I've ensured via a PHP fileexists function that ../templates/Export Template.xlsx can be found.

if (!file_exists("../templates/Export Template.xlsx")) { echo("file does not exist");}


Jun 5, 2012 at 12:15 AM
Edited Jun 5, 2012 at 12:22 AM

I have an update to this post.  I used one of the example PHPExcel programs to create an Excel export, which I was able to get the following code to read in:


/** PHPExcel_Writer_Excel2007 */
include './PHPExcel/Writer/Excel2007.php';
include './PHPExcel/Reader/Excel2007.php';


function create_excel_file($report_row_IDs) {
	if (file_exists("../templates/test.xlsx")) {
		echo("test.xlsx exists\n");

	$objReader = new PHPExcel_Reader_Excel2007();
	$objPHPExcel = $objReader->load("../templates/test.xlsx");

The code results in "test.xlsx exists 01".

When I deleted the content from the working Excel file and replaced it with the current content I need to get working, it failed (as seen in the "code results in" line).  I'm not sure what the content of the file is that causing it to fail, or if it's a size issue (2.22 megabytes), but I'd love any input I can get.  I'm not sure how to attach files, or else I'd include the working and non-working Excel files.  If I get any interest, I can email the file or post it somewhere for retrieval.