Open Existing XLS File & Edit it

Topics: Developer Forum, Project Management Forum, User Forum
Feb 11, 2015 at 4:35 PM
Hello,

I have the following code to open a specific XLS file and edit it:
require_once 'Classes/PHPExcel/IOFactory.php';

    $objPHPExcel = PHPExcel_IOFactory::load("default/ws-data.xls");

    $objPHPExcel->setActiveSheetIndex(0);

    $objPHPExcel->setCellValue('A2', $session_id);
    $objPHPExcel->setCellValue('B2', 'c5fnh09adtc0');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('ws-data.xls');
The file is the following one --> https://www.dropbox.com/s/3ozn386q9ihd259/ws-data.xls?dl=0

Any help would be appreciated.

Yours Sincerely,
Henry
Coordinator
Feb 11, 2015 at 4:38 PM
Besides the fact that you're saving to a different folder than you're loading from, what exactly is the problem?
Feb 11, 2015 at 4:41 PM
Hello,

I was trying to load the file from a location that contains the default XLS files, and then save it to the proper location.

The error that is displaying is still the same and is the following:

Fatal error: Call to undefined method PHPExcel::setCellValue() in /Users/admin/Sites/index.php on line 20

Also the line in which the error is pointing to is "$objPHPExcel->setCellValue('A2', $session_id);".

Yours Sincerely,
Henry
Coordinator
Feb 11, 2015 at 4:50 PM
Edited Feb 11, 2015 at 4:51 PM
That's easily solved.... Spreadsheets (PHPExcel objects) have Worksheets, and Worksheet's have cells

You need to get/set cells in a worksheet:
$objPHPExcel->getActiveSheet()->setCellValue('A2', $session_id);
And you have various documented methods for changing the active worksheet, getting a sheet by name or by index position, etc
Feb 12, 2015 at 8:39 AM
Hello,

I changed the line to that and the problem was solved. But now the errors that are appearing are beyond my understanding, if you can help I would appreciate it:
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 476

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 476

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 476

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 477

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 477

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 477

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 476

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 476

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 476

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 477

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 477

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for 'WET/0.0/no DST' instead in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE.php on line 477

Warning: fopen(ws-data.xls) [function.fopen]: failed to open stream: Permission denied in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE/PPS/Root.php on line 90

Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open ws-data.xls. It may be in use or protected.' in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE/PPS/Root.php:93 Stack trace: #0 /Users/admin/Sites/Classes/PHPExcel/Writer/Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('ws-data.xls') #1 /Users/admin/Sites/index.php(24): PHPExcel_Writer_Excel5->save('ws-data.xls') #2 {main} thrown in /Users/admin/Sites/Classes/PHPExcel/Shared/OLE/PPS/Root.php on line 93
Any help would be appreciated.

Yours Sincerely,
Henry