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

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

我在尝试添加 table 的新行时出错,一切正常,我可以将我的 html 页面导出到 ms word。

我遇到这样的错误

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

这是我的代码

        <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>

在我添加新行 table 之前,我已经完成了导出,我在上面遇到了错误

当我在此行之后添加新行时发​​生错误

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

参考documentation:

header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from 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. The same problem exists when using a single PHP/HTML file.

<?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>