gpt4 book ai didi

PHPExcel 将 xls 文件保存到特定文件夹

转载 作者:可可西里 更新时间:2023-11-01 00:09:10 25 4
gpt4 key购买 nike

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

  $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');

但我不断收到以下错误:

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

请告知在服务器上保存文件的最佳方式。

最佳答案

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

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

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

关于PHPExcel 将 xls 文件保存到特定文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22603237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com