dqf2015 2017-06-19 12:26
浏览 39
已采纳

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

Hello I write PHP header for downloading excel.

If I have 1 table I can set the width of <td> successfully by use width attribute

but if I have two table it's not working. How could I do? because I need multiple table in my excel page file

<?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>
  • 写回答

1条回答 默认 最新

  • dsdtszi0520538 2017-06-19 17:18
    关注

    Excel, when reading HTML files, really only has one HTML table. If you look at the Excel window you'll see that physically it's just a single table. If you insist on separating the data (which makes no difference to Excel) you can use multiple table bodies:

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

    Output:

    screenshot of Excel

    By the way, you are abusing MIME types terribly here! This document is not application/vnd.ms-excel or application/xhtml+xml, it's text/html and should not be saved with an XLS extension. Excel can read HTML files, but that doesn't make HTML files Excel files!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?