PHPExcel_Reader issues with Excel versions below 2010

Topics: Developer Forum, Project Management Forum, User Forum
Nov 14, 2012 at 7:25 PM
Edited Nov 14, 2012 at 7:44 PM


I am using PHPExcel_Writer to write some data from a database into a spreadsheet for the user to edit. User downloads this spreadsheet from my website, fills it in and uploads the filled file onto the website.  The file is then read by the server code using PHPExcel_Reader. 

The original spreadsheet contains 3 worksheets: first is editable by user; second and third are hidden.  The second worksheet contains named ranges that correspond to database values (some contain special characters such as single quotes or commas).  The third worksheet contains a hidden database identifier.

The template can be downloaded and opened on the user's workstation just fine (tested on CentOS LibreOffice, Excel 2007+2010 on Windows, and Excel 2008+2011 on Mac). 

HOWEVER, after the sheet is saved, the following problems occur with LibreOffice and Excel2007 and 2008:

1. If the file is saved on the user's workstation, filled, saved, closed (exit Excel) and reopened, the named ranges references are lost in LibreOffice on CentOS 6.2.

2. The completed workbook can be uploaded onto the server BUT is not read by  PHPExcel_Reader IFF Excel 2007 (win) or 2008 (mac) were used for editing:


$objReader = PHPExcel_IOFactory::createReader('Excel2007');

// alternatively, can use this - also works
// $objReader = new PHPExcel_Reader_Excel2007(); // this works too

$objReader->setReadDataOnly(true); $filename = $_FILES["my_file"]["name"]; $uploaddir = 'mydir/'; $uploadfile = $uploaddir . $filename; if (move_uploaded_file($_FILES["my_file"]["tmp_name"], $uploadfile)) { // THIS WORKS FOR ALL echo "File is valid, and was successfully uploaded.\n"; echo "<a href='" . $uploadfile . "'>file"; try { // THIS WORKS $objPHPExcel = $objReader->load($uploadfile); // THIS FAILS ON EXCEL 2007 AND 2008, WORKS ON 2010 $sheets = $objPHPExcel->getAllSheets(); $objWorksheet = $sheets[0]; // NULL ON EXCEL 2007 AND 2008 }

Any help is appreciated!