[英]How to generate excel file (xls) and save it to a server location without downloading it using ColdFusion
我們有一個生成動態內容的頁面,並且根據用戶的選擇輸出格式。
例如,如果用戶選擇了 HTML 格式,則頁面將作為 HTML 頁面出現。 這工作正常以及 PDF 格式。
挑戰在於,如果用戶選擇 Excel 格式並且我們需要將 Excel 文件保存到服務器。
當用戶選擇 Excel 格式時,文件在 excel 中生成就好了,但是,用戶沒有將其保存到服務器,而是獲得“另存為”對話框,但是,正如我提到的,我們需要將文件保存到服務器。
非常感謝任何輸入。 我們正在使用 CF 2016。
代碼示例:
<cfsavecontent variable="Page">
<cfif CompareNoCase(FORM.format,"xls")>
<cfsetting enablecfoutputonly="Yes">
<cfheader name="Content-Disposition" value="attachment;filename=""#VARIABLES.vcFilename#""">
<cfcontent type="application/vnd.msexcel">
<cfif>
<table><tr><td><cfoutput>#somecontent#</cfoutput></td></tr>...</table>
</cfsavecontent>
<cfif CompareNoCase(FORM.format,"xls")>
<cffile
action="write"
destination="d:\somedir\"
file="#VARIABLES.vcFileName#"
output="#Page#"
nameconflict="overwrite">
<cfif>
正如 SOS 在評論中提到的,他刪除標題的建議成功了。 另外,為了保存 excel 文件 (.xls),在 cffile 中添加了以下內容:accept="application/vnd.ms-excel,application/xls"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.