Save loaded Excel

Topics: User Forum
Nov 29, 2010 at 6:12 PM

Hi!

Can anyone tell me how to save a loaded Excel file without creating a new writer object?

Thanks in advance for the help,

Best regards! 

Coordinator
Nov 29, 2010 at 7:47 PM
Edited Nov 29, 2010 at 7:49 PM

You can't: without a Writer, there's nothing in PHPExcel that provides any mechanism to write/save the PHPExcel object.

Nov 29, 2010 at 10:11 PM
Edited Nov 29, 2010 at 10:11 PM

So, how can I save the changes to a loaded Excel file, without changing its name?  

Coordinator
Nov 29, 2010 at 10:14 PM
ruigoncalves wrote:

So, how can I save the changes to a loaded Excel file, without changing its name?  

 When you save the file, instantiate the appropriate Writer, and save it with the same name as the original. 

Nov 30, 2010 at 3:12 PM

Considering what you said on your previous, can you confirm me if the following code snippet will work properly?

 

/** Error reporting */

error_reporting(E_ALL);

/** PHPExcel_IOFactory */

require_once '../Classes/PHPExcel/IOFactory.php';
// load the excel

document$objPHPExcel = PHPExcel_IOFactory::load("teste.xls");

// save the file

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter->save('teste.xls');

echo "\n";echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

Thanks in advance for the help,

Best regards!

Coordinator
Nov 30, 2010 at 10:39 PM

Aside from document$objPHPExcel (which I assume is a cut and paste error), this should work. Why not try it and see.