PHPExcel将xls文件保存到特定文件夹 [英] PHPExcel Save a xls file to a specific folder

查看:499
本文介绍了PHPExcel将xls文件保存到特定文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下代码使用Php Excel将xls文件保存到服务器上的特定文件夹中:

I want to save a xls file to a specific folder on the server using Php Excel using the following code :

  $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5');
//force user to download the Excel file without writing it to server's HD

        $objWriter->save('‪C:/xampp/htdocs/timesheet/files/test.xls');

但是我继续遇到以下错误:

But I keep on getting the following error :

A PHP Error was encountered

Severity: Warning

Message: fopen(‪C:/xampp/htdocs/timesheet/files/test.xls): failed to open stream: Invalid argument

Filename: PPS/Root.php

Line Number: 90


    Fatal error: Uncaught exception 'PHPExcel_Writer_Exception' with message 'Can't open ‪C:/xampp/htdocs/timesheet/files/test.xls. It may be in use or protected.' in C:\xampp\htdocs\timesheet\application\third_party\PHPExcel\Shared\OLE\PPS\Root.php:93 Stack trace: #0 C:\xampp\htdocs\timesheet\application\third_party\PHPExcel\Writer\Excel5.php(226): PHPExcel_Shared_OLE_PPS_Root->save('???C:/xampp/htd...') #1 C:\xampp\htdocs\timesheet\application\controllers\time_sheet.php(6131): PHPExcel_Writer_Excel5->save('???C:/xampp/htd...') #2 [internal function]: Time_sheet->save_time_sheet() #3 C:\xampp\htdocs\timesheet\system\core\CodeIgniter.php(359): call_user_func_array(Array, Array) #4 C:\xampp\htdocs\timesheet\index.php(202): require_once('C:\xampp\htdocs...') #5 {main} thrown in C:\xampp\htdocs\timesheet\application\third_party\PHPExcel\Shared\OLE\PPS\Root.php on line 93

请提供有关将文件保存在服务器上的最佳方法的建议.

Please advise on the best way to save the file on the server.

推荐答案

尝试将 $objWriter->save() 代码更改为以下内容:

Try changing the $objWriter->save() code to the following:

$objWriter->save(str_replace(__FILE__,'folder_path/filename.xlsx',__FILE__));

您可以根据需要更改文件名和文件类型.

You may change the filename and the file type depending on what you need.

这篇关于PHPExcel将xls文件保存到特定文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆