从PHP导出到Word不会在第一页之外传送标题

我将数据从PHP页面导出到Word文档,但标题并非在所有页面中都可用。 标题存在于第一页中,但不存在于Word文档的其他页面中。 这是我的代码,
function changeDetails()
{
    $bType = $this->input->post('textvalue');
    if ($bType == "word")
    {
        $this->load->library('table');
        $data['countrytoword'] = $this->AddEditmodel1->export();
        $this->table->set_heading('Name','Country','State','Town');
        $out =  $this->table->generate($data['countrytoword']); 
        header("Content-Type: application/vnd.ms-word");
        header("Expires: 0");
        header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
        header("Content-disposition: attachment; filename=$cur_date.doc");
        echo '<br><br>';
        echo '<strong>CountryList</strong><br><br>';
        print_r($out);
    }
}
<? if(isset($countrytoword)) { ?>
  <table align="center" border="0">
    <tr>
      <td>Name</td>
      <td>Country</td>
      <td>State</td>
      <td>Town</td>
    </tr>
    <? foreach($countrytoword as $dsasffd) { ?>
      <tr>
        <td><?= $dsasffd['dbName'] ?></td>
        <td><?= $dsasffd['dbCountry']; ?></td>
        <td><?= $dsasffd['dbState']; ?></td>
        <td><?= $dsasffd['dbTown']; ?></td>
  <? } } ?>
    </tr>
  </table>
    
已邀请:
如果您使用&lt; thead&gt;标记标题行你应该得到你想要的东西。所以这段代码变成了
 <table align="center" border="0"> 
 <thead>
 <tr> 
  <td> 
   Name 
  </td> 
  <td> 
   Country 
  </td> 
  <td> 
   State 
  </td> 
  <td> 
   Town 
  </td> 

 </tr> 
 </thead>
    
我不知道听众,但是你使用的是什么样的循环
<? foreach($countrytoword as $dsasffd) { ?>
      <tr>
        <td><?= $dsasffd['dbName'] ?></td>
        <td><?= $dsasffd['dbCountry']; ?></td>
        <td><?= $dsasffd['dbState']; ?></td>
        <td><?= $dsasffd['dbTown']; ?></td>
  <? } } ?>
TR标签在任何地方都没有关闭(除了最后一个)。     
为何选择Microsoft Word? 现在,两个解决方案: 如果您正确命名文件并正确设置MIME类型,则可以使用文件→打开对话框,从桌面上获取MS Word以打开HTML文件。 另一个选择是生成LaTEX,然后使用latex2rtf来生成RTF。有HTML到RTF转换器,RTF很简单,你可以做到,但LaTEX比RTF更容易制作,质量似乎比HTML到RTF更好。 使用系统调用来运行应用程序,如果数据敏感,则使用UUID命名文件,然后重定向。你甚至不需要制作标题,因为你的网络服务器应该知道如何处理RTF。     

要回复问题请先登录注册