How can I force a download of entry data to an excel file? The website I'm building enables users to book places on events. This is simply a form which creates an entry in a channel containing 2 fields: "related user" and "related event". In the control panel I've written a simple plugin which displays all the entries in that channel exactly the same as the control panel normally would do, but now I can display any fields I want instead of just title and post date.

My client wants to be able to export the entry data from the control panel into Excel (xls or csv). What's the simplest way to do this? I read somewhere about changing http headers to force a download of a file, so can I just force a browser download of a dynamically generated page containing a table of all that entry data?

When I say "force a download" I mean I probably just need a button that says "Export", but it should download the file instead of opening it in the browser.
Craft's HttpRequestService has a sendFile method (available via craft()-&gt;request-&gt;sendFile()).

The 3rd parameter is an optional $options array that accepts key => value pairs.  One of those is 'forceDownload' =&gt; true and when that is passed in, Craft will set the proper HTTP headers to force the given file to be sent to the browser as a download.

You could do this from inside an action in one of your plugin's controllers.  Something like:

public function actionDownloadFile()
{
    // Grab your file content from wherever you have it stored. Here, it's just hard coded into a string.
    $contents = 'row1column1,row2column2'.PHP_EOL.'row2column1,row2column2'.PHP_EOL;    

    // Call sendFile, giving it the name of the file to send, the contents and tell it to force a download to the browser.
    craft()-&gt;request-&gt;sendFile('filename.csv', $contents, array('forceDownload' =&gt; true));
}