5

I have a HTML form that, when you submit the form by clicking a button the application generates an Excel file using PHPExcel. Everything works fine, but when the excel file is big the waiting time is quite long. I would like to add a progress bar or show a percent complete value. My problem is that I don't know how to insert that in the form and update it continuously.

This is what I am looking to accomplish: enter image description here

EDIT:

My code is:

HTML form:

<form action="reporteexcel.php" name = "ExportForm" method="POST">
 <table>
[All different fields]
     <tr>
                <td style = "position:relative; top:1em;left:4em;">
                    <input type="submit"  value="Export to excel">
                    <input type="button" onclick="window.close();" value = "Cancel">
                </td>
            </tr>
        </table>

    </form>

In reporteexcel.php:

include 'PHPExcel_1.8.0/Classes/PHPExcel.php';
    include 'F1_Export.php';
    include 'F2_Export.php';
if ($Family == "F1")
    {
        exportF2 ($BasicInformation, $SupplierInformation, $PhysicalParameters, $Supplier, $Family);
    }   
    else if ($Family == "F2")
    {
        exportF2 ($BasicInformation, $SupplierInformation, $PhysicalParameters, $Supplier, $Family);
    }

And in F1_export and F2_export are the functions, which generates the excel files.

Mastor
  • 179
  • 4
  • 15
  • If you don't want to use an existing library -- do a little research in to AJAX. Your call to export could be handled via AJAX which could return updates to your current screen/form. – DragonYen Jun 16 '15 at 11:40
  • I already tried but it doesn't work (at least I didn't know how to make it work ;) ). I added a
    in the HTML, I added the AJAX file as well, but I don't know how to update continuosly from my php function that value...
    – Mastor Jun 16 '15 at 11:42
  • Read this http://stackoverflow.com/questions/15508784/progress-bar-update-progress –  Jun 16 '15 at 11:44
  • You would have to check and see if GenerateExcel() will give you an update (I don't have any clue). If it does, then on those updates you would pass data back to your original page. Javascript on that page would parse the information and update the page. – DragonYen Jun 16 '15 at 11:46
  • @RupomKhondaker Thx, I'll check it now. – Mastor Jun 16 '15 at 11:49
  • @DragonYen I have the total number of lines in the excel and I also know what line is being written in each moment, so with that information I can get the %. My problem is how to send that values with AJAX – Mastor Jun 16 '15 at 11:51
  • Do you have any part of the AJAX working? For example is the processing of the Excel file being handled in an AJAX yet? I'm just trying to figure out where you are at in the process. – DragonYen Jun 16 '15 at 13:38
  • In this part of the program, I don't use AJAX. It is just a simple HTML form with a submit button and in the php-file in the submit I call the function GenerateExcel(), which is in another php file (the reason of this is because I have another functions in that submit php file). I update now the question with the code to make it more clear – Mastor Jun 16 '15 at 14:03
  • 1
    Your first step then is to create a different PHP file to process the Excel file. Call it with an AJAX call. Then have the new PHP file send back responses that the original AJAX call can process and update the screen. Google "Simple AJAX tutorial" -- there are plenty to get you started. – DragonYen Jun 16 '15 at 14:15

1 Answers1

2

Use this library to upload your file, you can also show progress bar for your uploads: http://blueimp.github.io/jQuery-File-Upload/

To show progress for long-running PHP scripts: http://www.htmlgoodies.com/beyond/php/show-progress-report-for-long-running-php-scripts.html

Raja Amer Khan
  • 1,489
  • 10
  • 31
  • Hi! I don't want to upload any file. I have my data in a database and with that, I generate an excel file. – Mastor Jun 16 '15 at 11:40