Updating Existing Spreadsheet

Oct 28, 2009 at 6:35 PM
Edited Oct 28, 2009 at 6:39 PM

Hello All

Firstly, I am very sorry if this a basic question but I have tried looking through the examples and documentation and cant find a simple way to do the following:

  1. I have an existing complicated spreadsheet, with existing formatting and formulas across multiple sheets.
  2. I would like to simply insert some data (coming from some PHP variables) into a few cells across multiple sheets and then display the result to the user as a download.

I have been working on this project for about 5 days now and haven't gotten anywhere so if someone could help me I can't express how much that would. This is also for a non-profit cause.


Oct 29, 2009 at 12:15 AM
// standard includes
require_once './Classes/PHPExcel.php';
require_once './Classes/PHPExcel/IOFactory.php';

// read in the existing file
$objPHPExcel = PHPExcel_IOFactory::load("existingFile.xls");

// modify/insert data in worksheet cells
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'New Data');

// redirect output to client browser
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="newFile.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
Oct 29, 2009 at 12:20 AM

Hey Mark

I managed to write something similar in the end - the actual problem was a silent memory leak which I have managed to "solve" by moving this to a dedicated server.

Problems I am having now are that I have a few "drop downs" in the spreadsheet and these are taken away in the output file - any idea why this might be? I have tried to search the discussions but cant seem to find anything relating to drop downs? Also 3 formulas starting with IF & ROUND are also being removed.

Thanks again


Oct 29, 2009 at 12:24 AM

Can't comment on the "drop downs", but if you can tell me exactly what the formulas are, I can take a look at those.