如何使用 cakephp 在单个文档中生成多个 excel 工作表

How to generate multiple excel sheets in a single document using cakephp

我是 Cakephp 的新手,我需要生成带有选项卡的 Excel 报告(sheets)。如何使用 cakephp 在单个文档中生成多个 sheets。我的示例 Reports Controller 具有以下功能

class ReportsController extends AppController {
    Function emp()
    {

    $this->set('crumbName', 'EMP');      

        $this->Emp->recursive = 2;
        $data = $this->Emp->find('all');
        $this->set('rows',$data);
        $this->render('emp_xls','export_xls');
    }

    ...
}

在emp_xls.ctp文件中包含员工信息 这是

    STYLE type="text/css">
    .tableTd {
        border-width: 0.5pt;
        border: solid;
    }

    .tableTdContent {
        border-width: 0.5pt;
        border: solid;
    }

    #titles {
        font-weight: bolder;
    }
    </STYLE>
    <table>
        <tr>
            <td><b>Faculty</b></td>
        </tr>
        <tr>
            <td><b>Date:</b></td>
            <td><?php echo date("F j, Y, g:i a"); ?></td>
        </tr>
        <tr>
            <td></td>
        </tr>
            <?php 
       error_reporting(0);
    echo '<tr id = "titles">';
  echo '<td class="tableTdContent">employee_number</td>';
  echo '<td class="tableTdContent">first_name</td>';
  echo '<td class="tableTdContent">last_name</td>';         
  echo '</tr>';
    ?>  

    <?php 
    foreach($rows as $data)
        {
     echo '<tr>';
 echo '<td class="tableTdContent">'. $data['Emp']['employee_number'].'</td>';
 echo '<td class="tableTdContent">'.$data['Emp']['first_name'].'</td>';
echo '<td class="tableTdContent">'.$data['Emp']['last_name'].'</td>';
echo '</tr>';
            }
                    ?>
    </table>

export_xls.ctp

<?php
header ("Expires: Mon, 28 Oct 2008 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/vnd.ms-excel");
header ("Content-Disposition: attachment; filename=\"Report.xls" );
header ("Content-Description: Generated Report" );
?>
<?php echo $content_for_layout ?> 

这些信息会填充到excel sheet(Single Sheet),那么现在如何在同一个文档中生成两个sheet来导出数据?

嗯,首先,如果您确实想将数据导出为 xls 格式,您可能想使用一些基于 PHPExcel 的组件,例如 this 我相信您可以在文档中找到如何为您的 XLS 文档创建多个工作表。

如果你想展示 excel 内容的简历(我认为这就是你试图用那些 table 和 td 标签做的)可能你想要类似的东西加入 HTML。 Bootstrap Tabs 呢?