您好,欢迎来到步遥情感网。
搜索
您的当前位置:首页ajax使用phpexcel,php - PHPExcel download using ajax call - Stack Overflow

ajax使用phpexcel,php - PHPExcel download using ajax call - Stack Overflow

来源:步遥情感网

App::import('Vendor', 'PHPExcel/Classes/PHPExcel');

$objPHPExcel = new PHPExcel();

$objPHPExcel->getActiveSheet()->setTitle('ReceivedMessages');

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

$file_name = "kpi_form_".date("Y-m-d_H:i:s").".xls";

header("Content-Disposition: attachment; filename=$file_name");

// If you're serving to IE 9, then the following may be needed

header('Cache-Control: max-age=1');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter->save('php://output');

When I call above code directly from the browser, the result file is downloaded. But if I make an ajax call to above code, I don't get the download prompt. I can see from console tab that the ajax call was successfully completed and a bunch of random characters is seen in the response data. I'm assuming that is the excel object.

Does anyone know how I can achieve the download excel feature using ajax? I don't want to refresh the page. When the user clicks on the "export" button, there should be an ajax call to the php file and prompt the user to download.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- obuygou.com 版权所有 赣ICP备2024042798号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务