从 PHP 导出到 Word 时,标题不会超出第一页

发布于 2024-08-27 03:26:25 字数 1502 浏览 5 评论 0原文

我将数据从 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>

I exported data from a PHP page to a Word document but the header is not available in all pages.

Header is present in the first page but not in the other pages of the Word document.

Here is my code,

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅唱々樱花落 2024-09-03 03:26:25

如果您使用 标记标题行,元素你应该得到你想要的。所以这段代码就变成了

 <table align="center" border="0"> 
 <thead>
 <tr> 
  <td> 
   Name 
  </td> 
  <td> 
   Country 
  </td> 
  <td> 
   State 
  </td> 
  <td> 
   Town 
  </td> 

 </tr> 
 </thead>

If you mark the header row(s) with a <thead> element you should get what you want. So this code becomes

 <table align="center" border="0"> 
 <thead>
 <tr> 
  <td> 
   Name 
  </td> 
  <td> 
   Country 
  </td> 
  <td> 
   State 
  </td> 
  <td> 
   Town 
  </td> 

 </tr> 
 </thead>
谈下烟灰 2024-09-03 03:26:25

不知道听者的情况,但是使用

<? foreach($countrytoword as $dsasffd) { ?>
      <tr>
        <td><?= $dsasffd['dbName'] ?></td>
        <td><?= $dsasffd['dbCountry']; ?></td>
        <td><?= $dsasffd['dbState']; ?></td>
        <td><?= $dsasffd['dbTown']; ?></td>
  <? } } ?>

TR 标签的这个循环是什么样的循环在任何地方都不会关闭(除了最后一个)。

don't know about hearder but what kinda loop is this u r using

<? foreach($countrytoword as $dsasffd) { ?>
      <tr>
        <td><?= $dsasffd['dbName'] ?></td>
        <td><?= $dsasffd['dbCountry']; ?></td>
        <td><?= $dsasffd['dbState']; ?></td>
        <td><?= $dsasffd['dbTown']; ?></td>
  <? } } ?>

the TR tag is not closing(except last one) anywhere.

茶花眉 2024-09-03 03:26:25

为什么选择微软Word?

现在,有两个解决方案:

  1. 如果您正确命名文件,并正确设置 MIME 类型,则当您使用 >文件→打开对话框。

  2. 另一个选择是生成 LaTEX,然后使用 Latex2rtf 制作 RTF。有 HTML 到 RTF 转换器,RTF 很简单,您可以制作它,但是 LaTEX 比 RTF 更容易制作,而且质量似乎比 HTML 到 RTF 更好。
    使用系统调用运行应用程序,如果数据敏感,则使用 UUID 命名文件,然后重定向。您甚至不需要制作标头,因为您的 Web 服务器应该已经知道如何处理 RTF。

Why Microsoft Word?

Now, two solutions:

  1. If you name the file correctly, and set your MIME type correctly, you may be able to get MS Word to open the HTML file, just as you can from the desktop, when you use the File → Open dialog.

  2. Another option is to generate LaTEX, then use latex2rtf to make RTF. There are HTML to RTF converters, and RTF is simple enough that you could make it, but the LaTEX is easier to make than RTF and the quality seems to be better than HTML to RTF.
    Use a System call to run the application, naming the file using a UUID if the data is sensitive, and then redirect. You would not even need to make the headers, as your web server should know what to do with an RTF already.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文