PHPExcel的输出问题


Output issues with PHPExcel

我有一个网页,其中用户选择要显示的行数,然后是导出数据到excel的表单中的按钮。

<form method="post" action="">
     <input type="Submit" name="excel" value="Export" class="button">
</form>

我能够获得数据,并将其放入excel文件与以下

if($_POST['excel']){
        $phpExcel = new PHPExcel();
        $styleArray = array(
            'font' => array(
            'bold' => true,
            )
        );
        //Get the active sheet and assign to a variable
        $foo = $phpExcel->getActiveSheet();
        //add column headers, set the title and make the text bold
        $foo->setCellValue("A1", "Nombre")
            ->setCellValue("B1", "Paterno")
            ->setCellValue("C1", "Pkey")
            ->setCellValue("D1", "Telefono")
            ->setCellValue("E1", "Ciudad")
            ->setCellValue("F1", "Used")
            ->setTitle("Contactos Encuestas")
            ->getStyle("A1:F1")->applyFromArray($styleArray);
        $xlsRow = 1;
        foreach ($rows as $column) {
            $foo->setCellValue("A".$xlsRow++, $column[2])
                ->setCellValue("B".$xlsRow++, $column[3])
                ->setCellValue("C".$xlsRow++, $column[0])
                ->setCellValue("D".$xlsRow++, $column[1])
                ->setCellValue("E".$xlsRow++, $column[5])
                ->setCellValue("F".$xlsRow++, $column[4]);
        }
        header("Content-Type: application/vnd.ms-excel");
        header("Content-Disposition: attachment; filename='"ENcuestas_Contactos.xls'"");
        header("Cache-Control: max-age=0");
        $objWriter = PHPExcel_IOFactory::createWriter($phpExcel, "Excel5");
        $objWriter->save("php://output");
        $phpExcel->disconnectWorksheets();
        unset($phpExcel);
    }

这有点工作,问题是奇怪的文字连同网页元素,如按钮和图像被放到excel文件。

有什么问题吗?

是否缺少设置?

发现为什么我在excel文件中获得HTML元素。

我把PHP代码放在HTML中。

将PHP代码放在<html>代码之外,并显示excel文件,没有任何问题。