hi there
I have a class in php(PHPExcel) which help me generate excel files but I get an error when I need to override on existing (previous) xls file.
the server is ubuntu(linux distr)
| SitePoint Sponsor |

hi there
I have a class in php(PHPExcel) which help me generate excel files but I get an error when I need to override on existing (previous) xls file.
the server is ubuntu(linux distr)




Without more details its hard to diagnose but it sounds like some sort of permissions error. Any error codes?



It sounds most likely to be a permissions error... but what is the error that you are actually getting?

this is the error that I get:
Uncaught exception 'Exception' with message 'Can't open 01simple.xls. It may be in use or protected.'







Try the following, checking the protections on the file created between each call to the script.
Then try it again after addingPHP Code:error_reporting(E_ALL);
ini_set('display_errors', '1');
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/');
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
$excelFileName = 'testReadWrite.xls';
if (file_exists($excelFileName)) {
$objReader = PHPExcel_IOFactory::createReader('Excel5');
$objPHPExcel = $objReader->load($excelFileName);
} else {
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Counter');
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->setCellValue('B1', 0);
echo 'Creating new workbook<br />';
}
$objPHPExcel->setActiveSheetIndex(0);
$countValue = $objPHPExcel->getActiveSheet()->getCell('B1')->getValue();
echo 'Previous $countValue in B1 is '.$countValue.'<br />';
$countValue++;
echo 'New $countValue in B1 is '.$countValue.'<br />';
$objPHPExcel->getActiveSheet()->setCellValue('B1', $countValue);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($excelFileName);
as a new bottom line afterPHP Code:chmod($excelFileName,0777);
PHP Code:$objWriter->save($excelFileName);

many thx mark for your support and for the PHPExcel. great product
I've find the reason for my errors. I can't overwrite .xls files created on windows station(WAMP) also using PHPExcel(same web application).
Do you have a solution for this, or is better to detele the file before I save it to hdd server.



I don't have a solution because I've never encountered the problem. The script I gave in my post above works for me quite happily on both Windows and Linux servers, as long as the destination directory privileges are set up correctly for the account that Apache is running under.
Your solution might provide a workround. You seem to have no problems with creating a new file, or reading an existing file; only with over-writing an existing file. The only question is: if it is a permissions related issue, will you be able to unlink the old file from within your script?
I'll do some playing around, see if I can recreate the situation that you're having

hi there
- same thing is happening in linux if i copy a excel file generated by other user and i try to write over it using PHPExcel
- I've tryed chmod($excelFileName, 0777 ); but I get the following message error:
Warning: chmod() [function.chmod]: Operation not permitted in ....
Bookmarks