PHPExcel generate Excel files --- prompt export file or the file name extension is inconsistent, or export files or invalid file extension

Data :: = Db name $ ( 'shop_cart') -> WHERE ( 'Phone', '15,555,555,555') -> SELECT (); 
        $ objPHPExcel new new PHPExcel = (); // instantiate PHPExcel new class equivalent on the desktop an Excel spreadsheet 
        $ objSheet = $ objPHPExcel-> getActiveSheet ( ); // get the current active sheet of the operation target 
        $ objSheet-> setTitle ( 'demo' ); // to set the name of the currently active sheet 
        $ objSheet-> setCellValue ( "A1 "," serial number ") -> setCellValue (" B1 "," number "); 
        $ objSheet-> setCellValue (" a C1 "," product name ") -> setCellValue (" D1 "," specifications "); 
        $ objSheet-> setCellValue ( "E1", " concentration") -> setCellValue ( "F1 ", " List"); 
        $ objSheet-> setCellValue ( "Gl", "price") -> setCellValue ( "H1 ", " delivery ");
        $ objSheet-> setCellValue ( "I1" , " valid") -> setCellValue ( "J1 ", " batch number"); 
        $ objSheet-> setCellValue ( "K1", "supplier") -> setCellValue ( " L1 "," number "); 
        $ objSheet-> setCellValue ( "M1", "money") -> setCellValue ( "N1 " "Notes"); 
        $ J = 2;
        foreach($data as $key => $val){
            if($val['good_stock'] > 50){
                $val['good_stock'] = '有货';
            }else if($val['good_stock'] < 50 && $val['good_stock'] > 50){
                $val['good_stock'] = '缺货';
            }else{
                $val['good_stock'] = '暂无';
            }
            $val['good_indate'] = date('Y-m-d',$val['good_indate']);
            $objSheet->setCellValue("A".$j,$key+1)->setCellValue("B".$j,$val['good_num'])->setCellValue("C".$j,$val['good_name'])->setCellValue("D".$j,$val['good_spe'])->setCellValue("E".$j,$val['good_standard'])->setCellValue("F".$j,$val['normal_price'])->setCellValue("G".$j,$val['member_price'])->setCellValue("H".$j,$val['good_stock'])->setCellValue("I".$j,$val['good_indate'])->setCellValue("J".$j,$val['good_batch'])->setCellValue("K".$j,$val['company'])->setCellValue("L".$j,$val['good_count'])->setCellValue("M".$j,$val['good_subtotal'])->setCellValue("N".$j,''); 
        header (' the Content-Disposition: Attachment; filename = "links_out. xls " ');
        header (' the Type-the Content: file application / vnd.ms-Excel ');
        ob_end_clean (); // clear the buffer, to avoid distortion
        }
            $ J ++;
        header (' the Cache-Control: max-Age = 0 ') ;
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');

  Before how do downloaded files are malformed. Not already familiar with the Excel file, do not use, the results dizzy with between 2003 and 2007, in fact, write right,

Just not clear buffer 
ob_end_clean ();

Invalid, it will prompt export file or the file name extension is inconsistent, or export files or file extensions, now Excel5 is no problem, but Excel2007 still unsuccessful, also need to continue to adjust

Guess you like

Origin www.cnblogs.com/dayin1/p/11693597.html