简体   繁体   English

为什么在将 html 页面导出到 word 时出现错误?

[英]Why am i getting an error while exporting html page to word?

i got an error while trying to add new row of the table, everything is normal and i can export my html page to ms word.尝试添加表格的新行时出现错误,一切正常,我可以将 html 页面导出到 ms 字。

im getting error like this我收到这样的错误

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\exportword2.php:216) in C:\xampp\htdocs\test\exportword2.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\exportword2.php:216) in C:\xampp\htdocs\test\exportword2.php on line 218

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\exportword2.php:216) in C:\xampp\htdocs\test\exportword2.php on line 219

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\exportword2.php:216) in C:\xampp\htdocs\test\exportword2.php on line 220

here is my code这是我的代码

        <tr>
            <td>13. </td>
            <td>Upah Pekerja</td>
            <td>:</td>
            <td>Minimum</td>
            <td colspan="4">Rp. 100000</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td>:</td>
            <td>Maximum</td>
            <td colspan="4">Rp. 100000</td>
        </tr>
        <tr>
            <td></td>
            <td>Upah Pekerja Harian</td>
            <td>:</td>
            <td>Minimum</td>
            <td colspan="4">Rp. 100000</td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td>:</td>
            <td>Maximum</td>
            <td colspan="4">Rp. 100000</td>
        </tr>
        <tr>
            <td>14.</td>
            <td>Sistem Hubungan Kerja</td>
            <td colspan="6">:</td>
        </tr>
        <tr>
            <td></td>
            <td>a. Untuk Waktu Tertentu</td>
            <td colspan="6">: 3 Orang</td>
        </tr>
        <tr>
            <td></td>
            <td>b. Untuk Waktu Tidak Tertentu</td>
            <td colspan="6">: 3 Orang</td>
        </tr>
    </table>


    <?php
            header("Content-Type: application/vnd.msword");
            header("Expires: 0");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("content-disposition: attachment;filename=hasilekspor.doc");
    ?>

</body>

i already done exporting until i add new row of table, i got an error above我已经完成了导出,直到我添加了新的表格行,上面出现了错误

error occure when i add new row after this row当我在此行之后添加新行时发生错误

<tr>
    <td>13. </td>
    <td>Upah Pekerja</td>
    <td>:</td>
    <td>Minimum</td>
    <td colspan="4">Rp. 100000</td>
</tr>

refer to the documentation :请参阅文档

header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. header() 必须在发送任何实际的 output 之前调用,无论是通过普通的 HTML 标记、文件中的空行还是来自 PHP。 It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called.在调用 header() 之前,使用 include 或 require 函数或其他文件访问 function 读取代码是非常常见的错误,并且在 output 中有空格或空行。 The same problem exists when using a single PHP/HTML file.使用单个 PHP/HTML 文件时也存在同样的问题。

<?php
// header must be before any sent output 
header("Content-Type: application/vnd.msword");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=hasilekspor.doc");
 ?>
<html>
...
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM