下载文件未启动时加载按钮

时间:2016-06-28 05:32:14

标签: php jquery twitter-bootstrap phpexcel

我希望我的用户下载一个PHPExcel文件,我希望我的按钮禁用并说明加载...而文件没有开始下载。问题是下载按钮是从我的数据库MySql获取数据,以放入生成此文件所需的Excel格式的每个单元格。我找不到这种类型的问题的答案。提前谢谢。

这是我生成Excel文件的PHP代码。

    if(isset($_POST['dl_xls'])){
    include_once('php/connection.php');
    include('Classes/PHPExcel.php');
    require_once "Classes/PHPExcel/IOFactory.php";

    //auto generate PR number >>>

        $sql_check_exist = "SELECT pr_digits_ID FROM pr_digits WHERE PR_ID ='".$pr_id."' LIMIT 1";
        $query_check_exist = mysqli_query($db,$sql_check_exist);
        $sql_max_digits = "SELECT MAX(pr_digit) AS max_digit FROM pr_digits WHERE year ='".$year."' AND month = '".$month."' ORDER BY pr_digits_ID DESC LIMIT 20";
        $query_max_digits = mysqli_query($db,$sql_max_digits);

        if(mysqli_num_rows($query_check_exist) == 0){

            if(mysqli_num_rows($query_max_digits)>0){

                $r_d = mysqli_fetch_array($query_max_digits);
                $max_digit = $r_d['max_digit'];
                $max_digit += 1;
                $sql_add_digit= "INSERT INTO pr_digits (PR_ID, year, month, pr_digit) VALUES ('".$pr_id."','".$year."', '".$month."', '".$max_digit."')";
                mysqli_query($db,$sql_add_digit);
                $dig = sprintf('%03d',$max_digit);
                $c = $year.'-'.$month.'-'.$dig;

            }else{

                $r_d = mysqli_fetch_array($query_max_digits);
                $max_digit = 1;
                $sql_add_digit = "INSERT INTO pr_digits (PR_ID, year, month, pr_digit) VALUES ('".$pr_id."','".$year."', '".$month."', '".$max_digit."')";
                mysqli_query($db,$sql_add_digit);
                $dig = sprintf('%03d',$max_digit);
                $c = $year.'-'.$month.'-'.$dig;

            }
        }else{

        }



    //<<<<<


    $col_no = 17;   
    //load template
    $obj_tmp = PHPExcel_IOFactory::load("src/dole_template.xls");
    $obj_tmp ->setActiveSheetIndex(0);
    while($data_row=mysqli_fetch_array($rsitems)){

        $obj_tmp -> getActiveSheet() -> SetCellValue('A'.$col_no, $data_row['quantity']);
        $obj_tmp -> getActiveSheet() -> SetCellValue('B'.$col_no, $data_row['unit_issue']);
        $obj_tmp -> getActiveSheet() -> SetCellValue('C'.$col_no, $data_row['item_des']);
        $obj_tmp -> getActiveSheet() -> SetCellValue('G'.$col_no, $data_row['unit_cost']);
        $obj_tmp -> getActiveSheet() -> SetCellValue('H'.$col_no, $data_row['total_cost']);
    $col_no = $col_no + 2;  
    }


        $obj_tmp -> getActiveSheet() -> SetCellValue('B7', $for_use);
        $obj_tmp -> getActiveSheet() -> SetCellValue('A12', $f_office);
        $obj_tmp -> getActiveSheet() -> SetCellValue('D12', $c);
        $obj_tmp -> getActiveSheet() -> SetCellValue('G12', $pr_date);
        $obj_tmp -> getActiveSheet() -> SetCellValue('B41', $pr_purpose);
        $obj_tmp -> getActiveSheet() -> SetCellValue('G41', $pr_brand);
        $obj_tmp -> getActiveSheet() -> SetCellValue('E43', $pr_reason);
        $obj_tmp -> getActiveSheet() -> SetCellValue('B47', $pr_year);

            ### Recommending Approval
            if($f_office === 'IMSD/PROPERTY' || $f_office === 'IMSD/PERSONNEL' || $f_office === 'IMSD/CASHIER' || $f_office === 'IMSD/DOCKET' || $f_office === 'OD' || $f_office === 'ARD/ADMIN'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'JULIE F. RODRIGUEZ');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'OIC-Chief, IMSD');

            }else if($f_office === 'EPWW' || $f_office === 'EPWW/LIVELIHOOD'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'AURORA E. HALCON');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'OIC, TSSD-EPWW');

            }else if($f_office === 'LRLS' || $f_office === 'LRLS/PLANNING'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'NELIA MUNGCAL');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'OIC, TSSD-LRLS');

            }else if($f_office === 'MALSU'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'ATTY. MARION SEVILLA');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Head, MALSU');

            }else if($f_office === 'COA'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'MILAGROS PILAR');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Audit Team Leader');

            }else if($f_office === 'ARD/LABOR'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'ATTY. MARIA CONSUELO S. BACAY');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Asst. Regional Director');

            }else if($f_office === 'MPFO'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'ROWELLA G. GRANDE');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Director II, MPFO');

            }else if($f_office === 'CFO'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'ANDREA P. CABANSAG');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Director II, CFO');

            }else if($f_office === 'MFO'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'LEONIDES CASTILLON JR.');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Director II, MFO');

            }else if($f_office === 'PFO'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'MA. CORAZON PEPITO');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Director II, PFO');

            }else if($f_office === 'MTPLFO'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'BENVENUTO C. ALEGRE');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Director II, MTPLFO');

            }else if($f_office === 'QCFO'){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E49', 'LILIBETH CAGARA');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E50', 'Director II, QCFO');

            }

            ### Approved
            if($total_s > 50000){

                $obj_tmp -> getActiveSheet() -> SetCellValue('E54', 'NELSON C. HORNILLA');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E55', 'OIC, Regional Director');
            }else{

                $obj_tmp -> getActiveSheet() -> SetCellValue('E54', 'IRMA S. VALIENTE');
                $obj_tmp -> getActiveSheet() -> SetCellValue('E55', 'Assistant Regional Director');
            }



        $obj_tmp -> getActiveSheet() -> SetCellValue('H39', $total_s);

    $filename= $c.'.xls';
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="'.$filename.'"');
    header('Cache-Control: max-age=0');
    $obj_writer = PHPExcel_IOFactory::createWriter($obj_tmp, 'Excel5');
    $obj_writer ->save('php://output');

    $update_pr_no = "UPDATE pr_table SET save = 1, pr_no='".$c."'  WHERE PR_ID = '".$pr_id."'";
        mysqli_query($db,$update_pr_no);
        mysqli_close($db);

我知道我需要在这里使用一些jquery来获得逻辑,但我不知道XD是如何得到一些简单的jquery来改变按钮内的文本。

    function button_ds() {
        _('add_btn').disabled = true;
        _('dl_xls').innerHTML = 'Click to go Back';

    }

发布dl_xls的HTML表单

    <form method="POST" role="form" id="dl_xls_frm">
                            <button type="submit" name="dl_xls" id="dl_xls" class="btn btn-success" onclick="button_ds()">Download Excel  <span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span></button>
                            </form>

再次感谢。

0 个答案:

没有答案