Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 生成excel文件时,PHPExcel弹出进度条或等待图标_Javascript_Php_Jquery_Ajax_Phpexcel - Fatal编程技术网

Javascript 生成excel文件时,PHPExcel弹出进度条或等待图标

Javascript 生成excel文件时,PHPExcel弹出进度条或等待图标,javascript,php,jquery,ajax,phpexcel,Javascript,Php,Jquery,Ajax,Phpexcel,我使用PHPExcel生成excel文件,但由于某些excel文件很大,生成需要时间 生成excel文件时,我希望添加一个弹出窗口,显示进度条或等待图标 我已经尝试了在谷歌上找到的所有解决方案,但仍然无法实现。 我感谢所有的帮助 $objPHPExcel = new PHPExcel();<br> $F=$objPHPExcel->getActiveSheet(); //other's code to generate excel file header('Content-

我使用PHPExcel生成excel文件,但由于某些excel文件很大,生成需要时间

生成excel文件时,我希望添加一个弹出窗口,显示进度条或等待图标

我已经尝试了在谷歌上找到的所有解决方案,但仍然无法实现。 我感谢所有的帮助

$objPHPExcel = new PHPExcel();<br>
$F=$objPHPExcel->getActiveSheet();

//other's code to generate excel file

header('Content-Type: application/vnd.ms-excel');<br>
header('Content-Disposition: attachment;filename="report.xls"');<br>
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');<br>
$objWriter->save('php://output');<br>
exit();

没有办法按照你提议的方式完成这项工作。首先,您正在创建的标题将不允许向用户显示html。此外,php还没有完成处理,因此在脚本完成之前无法返回给用户

另一个选项是从Javascript异步调用PHP脚本。然后将文件名返回到javascript,并将用户重定向到Excel文件。然后,您可以在网页上向用户显示您需要的任何内容。下面是一个非常简单的例子。但它可以让你开始

php:

jquery:

//Call to the php file above to start the processing
//You can add some spinner or popup message here
$.get( "path/to/phpexcel.php", function( data ) {
    //Now check the return data
    if(data.result === 200){
        //If all is well just redirect the user to the file
        window.location = data.path;
    }else{
        alert("Something went wrong!!!");
    }
});

同样,这是非常粗糙的,但我只是想让你有一个选择,进一步追求

既然这是一篇老文章,我就简短一点


如果在页面上放置一个iFrame,并将PHPExcel脚本加载到其中,并在某些点上放置回音以通知正在发生的事情,则可以对此进行模拟。另一个选项是将PHP_Excel脚本作为其自己的页面加载,并在脚本完成时显示“继续”或“返回”按钮。

谢谢!我会尝试一下。实际上我刚刚构建了类似的东西,但是像@James说的,你需要采用异步方法来更新页面,而不需要重新加载。我将在下面为你发帖。为了回答更接近OP的问题,你也可以用这种方式模拟一个加载条。您可以回显进度条上每个条上的img。确保每个img都向左浮动、向右清除和内联,以便它们在html中相互对接,形成一条直线。
$objPHPExcel = new PHPExcel();
$F=$objPHPExcel->getActiveSheet();
//Other code to Generate Excel File

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('path/to/excelfile.xls');

//Now return some info to user
//You will want to actually do some testing here
//to make sure the file was created
echo json_encode(array(
    "result" => 200,
    "path" => "path/to/excelfile.xls"
));
//Call to the php file above to start the processing
//You can add some spinner or popup message here
$.get( "path/to/phpexcel.php", function( data ) {
    //Now check the return data
    if(data.result === 200){
        //If all is well just redirect the user to the file
        window.location = data.path;
    }else{
        alert("Something went wrong!!!");
    }
});