gpt4 book ai didi

php - 在 Excel 中查看多个 HTML 表格时无法设置 TD 宽度

转载 作者:太空宇宙 更新时间:2023-11-04 08:33:34 24 4
gpt4 key购买 nike

你好,我编写了用于下载 excel 的 PHP header 。

如果我有 1 个表,我可以设置 <td> 的宽度使用宽度属性成功

但如果我有两个表,它就不起作用了。我怎么办?因为我的 excel 页面文件中需要多个表

<?php
header("Content-Type: application/vnd.ms-excel; charset=TIS-620");
header('Content-Disposition: attachment; filename="report_schedule_teacher.xls"');#ชื่อไฟล์

?>

<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=TIS-620" />


</head>
<body>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Hello1</td>
<td width="400">Hello2</td>
</tr>
</thead>
<tbody>
<tr>
<td>World1</td>
<td>World2</td>
</tr>
</tbody>
</table>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Why I cannot set width if I have multiple table</td>
<td width="400">Noooo</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
</tr>
</tbody>
</table>


</body>
</html>

最佳答案

Excel 在读取 HTML 文件时,实际上只有一个 HTML 表格。如果您查看 Excel 窗口,您会发现实际上它只是一个表格。如果你坚持分离数据(这对 Excel 没有影响),你可以使用多个表体:

<html>
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=TIS-620" />


</head>
<body>

<table width="100%" style="border-collapse: collapse;overflow:wrap; font-size:9pt;">
<thead>
<tr>
<td width="300">Hello1</td>
<td width="400">Hello2</td>
</tr>
</thead>
<tbody>
<tr>
<td>World1</td>
<td>World2</td>
</tr>
</tbody>

<thead>
<tr>
<td width="300">Why I cannot set width if I have multiple table</td>
<td width="400">Noooo</td>
</tr>
</thead>
<tbody>
<tr>
<td>kub</td>
<td>pom</td>
</tr>
</tbody>
</table>


</body>
</html>

输出:

screenshot of Excel

顺便说一句,你在这里严重滥用了 MIME 类型!此文档不是application/vnd.ms-excelapplication/xhtml+xml,它是text/html,不应使用XLS 扩展名。 Excel 可以读取 HTML 文件,但不能将 HTML 文件生成 Excel 文件!

关于php - 在 Excel 中查看多个 HTML 表格时无法设置 TD 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44630558/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com