简体   繁体   English

下载文件到服务器phpexcel + codeigniter

[英]download file to server phpexcel + codeigniter

I cant save file generated by PHPExcel to server. 我无法将PHPExcel生成的文件保存到服务器。 When do it 什么时候做

$this->load->library('Classes/PHPExcel');
$this->phpexcel->getActiveSheet()->setCellValue('A5','Value');
more excel code...

$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save('php://output');

I can download the file, but I tried many different ways to save the file in the server folder, for example 我可以下载文件,但是尝试了多种方法将文件保存在服务器文件夹中,例如

$filename = 'file.xls';
$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);
$writer->save($filename);

or use PHPExcel_IOFactory to save the file, but I cant get it to work, same idea pliss. 或使用PHPExcel_IOFactory保存文件,但我无法使它正常工作。

regards. 问候。

try this : 尝试这个 :

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$fname.'"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('./files/'.$fname);

Last night I solved the error. 昨晚我解决了错误。

$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="newFile.xls"');
header('Cache-Control: max-age=0');
$writer->setPreCalculateFormulas(false);

$writer->save(getcwd().'/mailAttachment/newFile.xls');

I add this line. 我添加这一行。

$writer->save(getcwd().'/mailAttachment/newFile.xls');

the function getcwd() get the current working directory. 函数getcwd()获取当前工作目录。

Thanks anyway. 不管怎么说,还是要谢谢你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM