繁体   English   中英

下载文件到服务器phpexcel + codeigniter

[英]download file to server phpexcel + codeigniter

我无法将PHPExcel生成的文件保存到服务器。 什么时候做

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

我可以下载文件,但是尝试了多种方法将文件保存在服务器文件夹中,例如

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

或使用PHPExcel_IOFactory保存文件,但我无法使它正常工作。

问候。

尝试这个 :

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

昨晚我解决了错误。

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

我添加这一行。

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

函数getcwd()获取当前工作目录。

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

暂无
暂无

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

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