[Catalyst] Re: displaying csv content (Octavian Rasnita)

Russell Jurney rjurney at lucision.com
Fri Feb 23 21:47:14 GMT 2007


Sending CSV is sufficiently simple that I haven't bothered with a  
View, although a view where an array is dumped to CSV might be  
worthwhile, just like the JSON view works.  There might be a more  
elegant way, but this is very, very easy.

In order to have the browser automatically save the file/open in  
excel, just add these lines:

	# Set the response content type to text/csv
	$c->response->content_type('text/csv');
	$c->response->header('Content-Disposition' => "attachment;  
filename=report.csv");

Then stash an array with your CSV data in it, and use a template like  
so:

[% FOREACH row = csv -%]
"[% row.0 -%]","[% row.1 -%]","[% row.2 -%]","[% row.3 -%]"...
[% END -%]

This works for me.  It took about 2 minutes, and my application now  
spits CSV. which is default opened in Excel.  Very simple 'Excel  
export.'

Russell Jurney
CEO   Lucision, Inc.
rjurney at lucision.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070223/fa07b3b4/attachment.htm


More information about the Catalyst mailing list