简体   繁体   中英

export generated table to excel

User interface of my web app is

在此处输入图片说明

First user selects country,city ,year and month. Based on this selection user clicks the display button. On clicking the display button it loads some javascript code which is

<script type="text/javascript">

    function tbl_display(){
     var sel_countryid= $("sel_country").val();
          var sel_cityid= $("#sel_city").val();
          var dataString = 'sel_countryid='+ sel_countryid+ '&sel_cityid='+ sel_cityid;  
         alert(dataString);
          if(sel_regionid=='' || sel_lbtype=='')
              {

                  alert("Please enter Valid Data");
              }
           else
           {
                $.ajax({
              type: "POST",
              url: "tbl_create.php",
              data: dataString,
              cache: true,
              success: function(html){
                      $("#result_table").html(html);
              }

              });

           }   

         } 
    </script>

In tbl_create.php page I have done sql query and echo the table .

when user clicks on this export button this table have to be exported to excel. My question is can I use the same query or I have to do another query to generate excel file

Thanks in advance.

You can use the same query to generate the Excel file. You can use php excel. Here is the link: PHP Excel Library

For optimization purposes, it is recommended to use the same query results. Check the PHP code sample from this link:

http://www.easyxls.com/manual/basics/export-list-to-excel.html

It uses EasyXLS Excel library for exporting to Excel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM