我有表格,我想在Excel中导出表格数据

时间:2019-07-15 07:23:13

标签: javascript php jquery ajax codeigniter

当前在我的页面中,单击按钮后即可打印,但我想在excel中获取数据

<form role="form" id="print_cash_challan" method="POST" enctype="multipart/form-data">
    <section class="content">
      <div class="row">
          <div class="table-responsive">
           <table id="gst_reporttable" class="table table-bordered  table-sm" style=" overflow: auto;">  </table>
          </div>
     </div>
    </section>
  </form>
<button id="print" name="print"  onclick="printContent('print_cash_challan')" class="btn btn-block btn-outline-primary fa fa-newspaper-o col-10 offset-1" style="margin-top: 35px; margin-bottom: 25px;" data-clicked="unclicked"> print Gst Report</button>

<script>
  $(document).ready(function($) {
    var from_date_bk       = "<?php echo isset($_POST['from_date_bk'])? $_POST['from_date_bk'] : '';  ?>";
    var to_date_bk         = "<?php echo isset($_POST['to_date_bk'])? $_POST['to_date_bk'] : '';  ?>";

    $.ajax({
     url :"<?php echo base_url(); ?>gst/GstController/printGstReport",
     type: 'POST', 
     async:false,              
     data: {
      from_date_bk:from_date_bk,
      to_date_bk:to_date_bk,

     },
     dataType: "html",
     success: function(data){
        console.log(data);
        $('#gst_reporttable').html(data);
     },
     error:function(data){
      console.log('error occured during fetch');
      /*alertify.error("error message"+data);*/
     }
  });
});

     function printContent(e1) {
     event.preventDefault();

      var restorepage     = document.innterHTML;
      var printContent    = document.getElementById(e1).innterHTML;
      document.innterHTML = printContent;
      window.print();
      document.location.href = "<?php echo base_url(); ?>"; 
      location.href="<?php echo base_url(); ?>gst/GstController/gstReportPage", 'refresh';
   }
</script>

我的控制器上有桌子。 在上面的代码中,我使用window.print()进行打印。 我不知道要在excel中导出。

1 个答案:

答案 0 :(得分:1)

尝试这个例子

<button name="submit" type="submit "class="btn btn-primary">