2016-04-08 10 views
0

私はCF 10を使用していますが、Save Asダイアログボックスが表示され、レポートを簡単に保存できるようにxls(Excel Extension)としてセーブタイプを設定しようとしています。優れたCF Save AsダイアログボックスでSave Type Asを設定

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

この質問を投稿する前に検索しましたか? :)質問する理由は、SOと主要な検索エンジンの両方で、cfheaderとcfcontentを使用してExcelのダウンロード(またはfaux-html-Excelのダウンロード)を生成する方法に関する記事が*たくさんあります。たとえば、http://stackoverflow.com/questions/4507973/how-can-i-download-to-excel/4547221#4547221 – Leigh

+0

私は本当に笑いました。しかし、これらを使って表示されている私の画面は、要求している名前を付けて保存ダイアログボックスに似ていません。そして、私はそれの例をまだhaventfoundしています:/ –

+0

@Leigh私は正しいタイプ=/ –

答えて

0

ジャストは、cfcontent後XLSファイル名で、次のcfheaderのを追加します。

< cfheaderの名= "コンテンツディスポジション" 値= "yourfilenameを.xls ">

+3

HTMLダウンロードダイアログは、デスクトップアプリケーションの[名前を付けて保存]ダイアログと同じではありません。ブラウザのセキュリティ上の理由により大きな制限があります。 「ファイル名」は、ブラウザを修正したり無視したりするための、単なる提案です。しかし、見ることは信じている。それを自分でテストし、何が起こるかを見てください。 – Leigh

関連する問題