2011-11-10 165 views
3

我正在使用PHPExcel将数据从我的PHP页面导出到Excel。 我正在使用Excel5。PHPExcel将文件保存到文件夹中或打开excel

我想要的Excel文件被保存了在代码

或者更好的是指定一个特定的文件夹,

我希望Excel与写在上面,使用户可以保存数据打开它在任何他想要的地方。 我该怎么做。

请指引我

回答

5

看01simple下载-xls.php在PHPExcel测试目录。这会将Excel文件发送到用户的浏览器,然后提示他们显示它(如果他们已安装Excel,或者其他电子表格程序(如果他们的扩展名与LibreOffice Calc或Gnumeric或其他相关的扩展名相关),或者将其保存到他们的本地磁盘。

+0

我越来越ZipArchive :: close()方法,同时节省phpexcel。 '$ objWriter-> save($ excel_path);' – 151291

+0

codeigniter中的路径格式是什么 –

7

这将询问用户保存/打开文件:

$excel = new PHPExcel(); 
header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="your_name.xls"'); 
header('Cache-Control: max-age=0'); 
// ... 
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5); 
$writer->save('php://output'); 
10

我解决了这个问题,这样做:

$objWriter->save(str_replace(__FILE__,'/path/to/save/filename.extension',__FILE__)); 

在我的情况下,它的工作!

+0

谢谢,这应该是接受的答案 – realtebo

+0

非常感谢你...... :) – Arya

+0

我得到ZipArchive :: close ()错误,同时保存phpexcel。 '$ objWriter->保存(str_replace函数(__ FILE __,$ excel_path,__ FILE __));' – 151291

1

这解决了这个问题对我来说:

$this->objWriter->save(str_replace(__FILE__,$_SERVER['DOCUMENT_ROOT'] .'/path/to/save/filename.xlsx',__FILE__));