CF另存为对话框并将类型另存为

时间:2016-04-08 14:36:58

标签: coldfusion

我正在使用CF 10,我正在尝试创建一个另存为对话框,并将保存类型设置为xls(Excel扩展),以便我的报告可以轻松保存在Excel中。我以为我可以用

做这件事
<cfelseif FORM.Format IS "xls">
    <cfcontent type="application/vnd.ms-excel">
    <cfheader name="Content-Disposition" value="inline; filename=fileName.xls">

但是没有打开正确的对话框。有谁知道如何实现这一目标?

这应该出现:enter image description here

    <cfelseif FORM.Format IS "xls">
    <cfcontent type="application/vnd.ms-excel">
    <cfheader name="Content-Disposition" value="inline; filename=fileName.xls">


    <cfset result = {} />
<cftry>
    <cfset date1 = CREATEODBCDATETIME(form.StartDate & '00:00:00')>
    <cfset date2 = CREATEODBCDATETIME(form.EndDate & '23:59:59')>

    <cfquery datasource="#application.dsn#" name="GetLocationInfo">
        SELECT  *
        FROM    cl_checklists
        WHERE   date >=  <cfqueryparam value="#date1#" cfsqltype="cf_sql_timestamp" />
                AND date <= <cfqueryparam value="#date2#" cfsqltype="cf_sql_timestamp" />
                AND trans_location IN ( <cfqueryparam value="#FORM.location#" cfsqltype="cf_sql_varchar" list="true" />  )
    </cfquery>

    <cfquery name="allLocCode" dbtype="query">
        SELECT DISTINCT trans_location, COUNT(*) AS locationCount FROM GetLocationInfo Where trans_location is not null GROUP BY trans_location ORDER BY trans_location
    </cfquery>

    <cfset columnSum = ArraySum(allLocCode['locationCount'])>
    <cfset checkListPercentage = arrayNew(1)>

<table border="1" id="Checklist_Stats">
  <thead>
    <th><strong>Location</strong></th>
    <th><strong>Percent of Total Checklists</strong></th>
    <th><strong>Location Total</strong></th> 
  </thead>
  <tbody>
    <cfloop query="allLocCode">
        <cfset thisLocationName = trim(allLocCode.trans_location) />

    <cfquery name="allLocCodeForLocationQry" dbtype="query">
        SELECT trans_location,count(*) AS locCntr FROM GetLocationInfo WHERE trans_location='#thisLocationName#' GROUP BY trans_location ORDER BY trans_location
    </cfquery>

    <cfoutput query="allLocCodeForLocationQry">
        <cfset currentPercentage = (allLocCodeForLocationQry.locCntr / columnSum * 100)>
        <cfset arrayAppend(checkListPercentage, currentPercentage)>
        <cfset totalPercentage = arraySum(checkListPercentage)>
    <tr>
      <td><strong>#thisLocationName#</strong></td>
      <td>#numberFormat(currentPercentage, '9.99')#%</td>
      <td>#allLocCodeForLocationQry.locCntr#</td>
    </tr>
   </cfoutput>
   </cfloop>
   <tr>
   <cfoutput>
    <td><strong>Total</strong></td>
    <td>#numberFormat(totalPercentage, '9.99')#%</td>
    <td>#columnSum#</td>
    </cfoutput>
  </tr>
  </tbody>
</table>

    <cfcatch type="any">
        <cfset result.error = CFCATCH.message >
        <cfset result.detail = CFCATCH.detail >
    </cfcatch>
</cftry>


    </cfcontent>

</cfif>

1 个答案:

答案 0 :(得分:0)

只需在cfcontent之后添加以下带有XLS文件名的cfheader:

  

&lt; cfheader name =“Content-Disposition”value =“yourfilename.xls”&gt;