Coldfusion CF“另存为”对话框和设置“另存类型为”
我正在使用CF 10,我正在尝试创建一个“另存为”对话框,并将“另存为”类型设置为xls(Excel扩展名),以便我的报告可以轻松地保存在Excel中。我在想也许我可以用这个Coldfusion CF“另存为”对话框和设置“另存类型为”,coldfusion,Coldfusion,我正在使用CF 10,我正在尝试创建一个“另存为”对话框,并将“另存为”类型设置为xls(Excel扩展名),以便我的报告可以轻松地保存在Excel中。我在想也许我可以用这个 <cfelseif FORM.Format IS "xls"> <cfcontent type="application/vnd.ms-excel"> <cfheader name="Content-Disposition" value="inline; filename=fi
<cfelseif FORM.Format IS "xls">
<cfcontent type="application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="inline; filename=fileName.xls">
但这并没有打开正确的对话框。有人知道如何做到这一点吗
这是应该出现的内容:
挑选*
从cl_清单
其中日期>=
和date只需在cfcontent之后添加以下带有XLS文件名的cfheader:
不是讽刺,而是。。。您在发布此问题之前搜索过吗?:)问这个问题的原因是有很多关于如何通过使用cfheader和cfcontent生成Excel下载(或伪html Excel下载)的帖子,包括SO和主要搜索引擎。例如,.我真的做了lol。但是我的屏幕上显示的这些与他们请求的另存为对话框不同。我还没有找到一个这样的例子:/@Leigh我添加了一个我一直得到的框的图像,它的类型不正确=/请停止删除你的所有/大部分评论。偶尔也可以,但如果所有内容都被删除,那么整个讨论的大量上下文也会被删除,而其他评论也不再有任何意义;-)记住,保留线程也是为了帮助他人,而不仅仅是帮助你。告诉用户这是不可能的。HTML下载对话框与桌面应用程序中的“另存为”对话框不同。出于安全原因,浏览器具有更大的限制。“文件名”只是对浏览器的一个建议,浏览器可以随意修改或忽略它。然而,眼见为实。自己测试一下,看看会发生什么。
<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>