使用外部样式表生成excel表的cfcontent样式

时间:2016-04-21 18:46:38

标签: coldfusion

我正在尝试将样式表合并到cfcontent标记中,该标记将生成Excel电子表格,如下所示。但是,即使样式表与显式引用链接,它也始终被忽略。什么可以确保Excel电子表格包含样式表?

<cfsetting enablecfoutputonly="Yes">
<cfsavecontent variable="sTest">
    <cfoutput>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
            <link rel="stylesheet" type="text/css" href="www.somesite.com/bootstrap/another.css" media="all">
            <link rel="stylesheet" type="text/css" href="../cssBootstrap/css/another.css" media="all">
        </head>
        <body>     
        <cfinclude template="../Reports/reportexportedasEXcel.cfm">
        </body>
    </cfoutput>
</cfsavecontent>
<cfcontent type="application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="attachment; filename=filename#DateFormat(now(),"mmdd")#-#TimeFormat(Now(),"HHMMSS")#.xls">  
<cfoutput>
    <html>      
    </head>
    <body>
        #sTest#
    </body>
    </html>
</cfoutput> 
</cfcontent>

1 个答案:

答案 0 :(得分:0)

将协议包含在样式表的链接中。 <link rel="stylesheet" type="text/css" href="http://www.somesite.com/bootstrap/another.css" media="all">

另一种选择是将样式表内容包含在xls文件中。

<cfset cssFilePath = getDirectoryFromPath(gettemplatePath()) & "../cssBootstrap/css/another.css" />
<cfset cssContent = fileRead(cssFilePath) />
</cfscript>
<html>
    <cfoutput>
        <head>
            <style>#cssContent#</style>
        </head>
    </cfoutput>