Ich benutze CF 10 und ich versuche, ein Speichern als Dialogfeld zu erstellen und legen Sie den Speichern als Typ wie xls (Excel Extension), so dass mein Bericht einfach gespeichert werden kann in Excel. Ich dachte, ich könnte dies vielleicht mitCF Speichern unter Dialogfeld und Einstellung Speichern unter
tun, aber das öffnet nicht das richtige Dialogfeld. Weiß jemand, wie das erreicht werden kann?
<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>
Nicht sarkastisch, aber ... haben Sie gesucht, bevor Sie diese Frage gestellt haben? :) Der Grund für die Frage ist, gibt es eine Menge Posts auf, wie man einen Excel-Download (oder faux-html-Excel-Download) durch die Verwendung von cfheader und cfcontent, sowohl auf SO und den wichtigsten Suchmaschinen. Zum Beispiel http://stackoverflow.com/questions/4507973/how-can-i-download-to-excel/4547221#4547221. – Leigh
Ich habe wirklich lol. Aber mein Bildschirm, der mit diesen erscheint, ist nicht wie das Dialogfeld Speichern als, das sie anfordern. Und ich habe noch kein Beispiel dafür gefunden:/ –
@Leigh Ich habe ein Bild der Box hinzugefügt, das ich bekomme, was nicht der richtige Typ ist =/ –