如何将HTML上的CSS应用于Excel导出 [英] How to Apply CSS on HTML to Excel export

查看:77
本文介绍了如何将HTML上的CSS应用于Excel导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php标头将HTML导出为Excel格式,但是CSS样式未应用到元素上(而导出为ex​​cel文件时),我也尝试实现Bootstrap类,但是没有运气

I am trying to export HTML to Excel format using php headers, but CSS styling is not applying on elements (while export to excel file), I also try to implement Bootstrap Classes, but no luck

注意:在应用引导程序类时,我在我的html中包含了bootstrap.css

Note: while applying bootstrap classes, I included the bootstrap.css in my html

有什么方法可以应用CSS?

Is there any way available to apply CSS?

标头使用

    header('Content-type: application/excel');        
    header("Content-Disposition: attachment; filename=\"$filename\"");

示例HTML元素

<table width="100%" border="1" class="table table-striped table-bordered">
    <thead>
        <tr>
            <td colspan="9" style="font-weight: bold; font-size: 16px; text-align: center;"><h2>Push Notification </h2></td>
        </tr>
        <tr><td colspan="9"></td></tr>
    </thead>

    <tbody>
        <tr class="heading">
            <th colspan="2" ></th>
            <th style="width:2% !important">S.no</th>
            <th style="width:10% !important">Date</th>
            <th style="width:10% !important">App</th>
            <th style="width:20%">Category</th>
            <th colspan="2" style="width:50%">Message</th>
        </tr>

        @if($push_notifications->count() > 0)
            <?php $counter = 1; ?>
            @foreach($push_notifications as $notification)
                <tr @if(($counter %2) ==1) bcolor="#c9c9c9" @endif>
                    <td colspan="2"></td>
                    <td style="width:2% !important">{!!$counter!!}</td>
                    <td style="width:10% !important">{!!$notification->date!!}</td>
                    <td style="width:10% !important">{!!$notification->notificationAppType->name!!}</td>
                    <td style="width:20%">{!!$notification->notificationCategory->name!!}</td>
                    <td colspan="2" style="width:50%">{!!htmlentities($notification->message, ENT_QUOTES)!!}</td>
                </tr>
                <?php $counter++; ?>
            @endforeach

        @else
                <tr>
                    <td colspan="9">No record available</td>
                </tr>
        @endif
    </tbody>
</table>

推荐答案

简短的回答是否,您不能将CSS应用于excel .

但是,您可以将某些格式应用于excel文件的文本,但是格式的数量受到用于生成excel文件的库以及excel本身允许的格式的限制.

You can, however, apply some formatting to the text of excel files, but the amount of formatting is limited by the library you use to generate the excel file and to what formatting the excel itself permits.

这篇关于如何将HTML上的CSS应用于Excel导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆