CodeIgniter Forums
.xls suffix on controller function to make excel file? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: .xls suffix on controller function to make excel file? (/thread-30026.html)



.xls suffix on controller function to make excel file? - El Forum - 04-29-2010

[eluser]Unknown[/eluser]
I know you can take a HTML table and change the extension to .xls to make it pop up as an xls file but I am trying to utilize this with code igniter MVC.

I have a form on one of my pages that takes the table from that page and dumps it into a function/view to put it out as a .xls page.

my URL ends up being something like this. www.siteurl.com/index.php/report/excel but when I add .xls onto it I get a 404.

It may be asking too much for CodeIgniter to accept www.siteurl.com/index.php/report/excel.xls instead of www.siteurl.com/index.php/report/excel.html

If anyone has any ideas or solutions for this I could really use the help.


.xls suffix on controller function to make excel file? - El Forum - 04-29-2010

[eluser]Ivan A. Zenteno[/eluser]
Maybe if you try setting the headers, could be work.


.xls suffix on controller function to make excel file? - El Forum - 04-30-2010

[eluser]mr_prasanna[/eluser]
www.siteurl.com/index.php/report/index/excel.html

You can probably try something like above and "excel.html" might be passed to index method inside your report controller. Also, you need to consider setting the Content-type header to something that triggers excel


.xls suffix on controller function to make excel file? - El Forum - 04-30-2010

[eluser]Unknown[/eluser]
Thanks for the direction on setting the MIME type

I ended up using the PHP header() method like so

Code:
header('Content-type: application/vnd.ms-excel');

header('Content-Disposition: attachment; filename="report.xls"');

I don't have the .xls on the url but all I wanted was for the link to make an excel file out of the current document anyway.

Thanks for the help!


.xls suffix on controller function to make excel file? - El Forum - 04-30-2010

[eluser]mr_prasanna[/eluser]
With a bit of .htaccess (ReWrite rule) you can get the .xls working too.