Jump to content

Return file from Process?


MadHatter
 Share

Recommended Posts

Hi, I'm trying to set up a tab in my admin area that, when clicked, will return a spreadsheet of all of the pages of a certain type (The template type is hard coded as it is for a single site for a client). I'm using PHPExcel which can output to php://output but I cannot find a way of preventing the template for the admin page from being output also. Is there a way to do this is is there another, more desirable method of achieving what I have aimed to do?

Thanks,

MadHatter

Link to comment
Share on other sites

You will want something like this:

public function ___execute() {
    $this->exportExcel();
}
public function exportExcel($event) {        
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=name.xls");
    header("Pragma: no-cache");
    header("Expires: 0");

    $this->outputExcel();
    exit;
}
public function outputExcel($data) {
    // your php://output" code
}

I used something like this is in: http://modules.processwire.com/modules/table-csv-import-export/

In that module you can test the behavior of downloading directly from a PW menu item by going to Pages > Admin > Setup > Table CSV Export and removing the hidden flag, then go to Setup > Table CSV Export and it will start a download directly from the process attached to that page. The module is not designed to be run directly from that helper page, but it will show you that it can work that way!

Hope that helps to get you started. 

  • Like 4
Link to comment
Share on other sites

That's what I thought. I ended up using:

$objWriter = new PHPExcel_Writer_Excel2007($spreadsheet);
header('Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=iso-8859-1');
header('Content-disposition:attachment; filename="Orkney Business Directory Listings.xlsx"');
$objWriter->save('php://output');
die();

at the end of my render function.

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...