Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExcelWriter taking SplFileObject as argument and deleting it - unlink issue #265

Open
tmilos opened this issue Sep 23, 2015 · 3 comments
Open

Comments

@tmilos
Copy link

tmilos commented Sep 23, 2015

ExcelWriter takes \SplFileObject as argument in constructor, but use it only to take filename. By default it uses Excel2007 type, which if file exists, unlinks it before reopening it, which results in error since SplFileObject created the file and opened handle on it.

Suggested solution, change ExcelWriter::__constructor to take argument string filename, rathen then\SplFileObject $file``

$filename = sprintf('%s/%s.xls', sys_get_temp_dir(), sha1(strtotime('now')));
$file = new \SplFileObject($name, 'w');
$result = $workflow
    ->addWriter(new ExcelWriter($fileObject, null, 'Excel2007'))
    ->process();

Warning: unlink(C:\Temp/7344836b29cf1d3e8f20a2b4e8aa889ebef69766.xls): Permission denied
in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007.php at line 229
lib version
ddeboer/data-import 0.18.0
phpoffice/phpexcel 1.8.1
php 5.5.19 win32
@Baachi
Copy link
Collaborator

Baachi commented Sep 23, 2015

Feel free to open a PR!

@PH-Lars
Copy link

PH-Lars commented Oct 12, 2015

The following works for me:

   $writer
            ->prepare()
            ->writeItem(array('first', 'last'));

        unset($file);

        $writer->finish();

@Marou023
Copy link

Marou023 commented Jun 8, 2016

How does you resolve that problem of export file in excel:
Warning : unlink(D:\test\data.xlsx): Permission denied in in vendor\phpoffice\phpexcel\Classes\PHPExcel\Writer\Excel2007.php at line 236 .

`$workflow = new Workflow($reader);

        $file = new \SplFileObject('D:\test\data.xlsx', 'w');
        $writer = new ExcelWriter($file);

      $workflow->addWriter($writer);
        $workflow->process();`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants