SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: phpexcel

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    phpexcel

    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)

  2. #2
    SitePoint Guru
    Join Date
    Feb 2008
    Posts
    655
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Without more details its hard to diagnose but it sounds like some sort of permissions error. Any error codes?

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds most likely to be a permissions error... but what is the error that you are actually getting?
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the error that I get:
    Uncaught exception 'Exception' with message 'Can't open 01simple.xls. It may be in use or protected.'

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dole.doug View Post
    It may be in use or protected
    So what permissions does the file have? what account/group owns it? and what account/group is your web server running as?
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  6. #6
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mark Baker View Post
    So what permissions does the file have? what account/group owns it? and what account/group is your web server running as?
    The file was previously created by PHPExcel.

  7. #7
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following, checking the protections on the file created between each call to the script.
    PHP 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); 
    Then try it again after adding
    PHP Code:
    chmod($excelFileName,0777); 
    as a new bottom line after
    PHP Code:
    $objWriter->save($excelFileName); 
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  8. #8
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dole.doug View Post
    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
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  10. #10
    SitePoint Zealot
    Join Date
    Dec 2008
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •