2014-01-27 42 views
1

我有一個生成多個電子表格對象的cfm頁面,現在如果我嘗試發送文件進行下載,只有最後生成的電子表格文件作爲下載發送。生成多個文件,將它們添加到一個zip文件,然後將該zip文件作爲文件下載文件發送。

有沒有辦法將這些文件寫入一個zip文件併發送zip文件作爲下載?

這是我現有的邏輯:現在

for(VARIABLES.fileNumber = 0; VARIABLES.fileNumber < VARIABLES.maxFiles; VARIABLES.fileNumber = VARIABLES.fileNumber + 1) 
{ 
    /* code to create Spreadsheet here */ 




    VARIABLES.context = getPageContext(); 
    VARIABLES.context.setFlushOutput(true); 

    VARIABLES.response = VARIABLES.context.getResponse().getResponse(); 
    VARIABLES.response.reset(); 
    VARIABLES.response.setContentType("application/msexcel"); 
    VARIABLES.response.setContentLength(len(SpreadsheetReadBinary(VARIABLES.suppItemSpreadSheetObj)));  
    VARIABLES.response.setHeader("Content-Disposition","attachment;filename=MyComplianceStatusFile#VARIABLES.fileNumber#Of#VARIABLES.maxFiles#.xls"); 

    VARIABLES.out = response.getOutputStream();  
    VARIABLES.out.write(SpreadsheetReadBinary(VARIABLES.suppItemSpreadSheetObj));  


    VARIABLES.out.flush();  
    VARIABLES.out.close(); 
    } 

,這樣我只得到生成的最後一個電子表格。有沒有辦法讓所有生成的電子表格可能是一個接一個,或可能在一個zip文件?

+2

另外,下載單個文件的方法更爲典型。 JSP。 CF中的標準(簡單)方法是使用['cfcontent'](https://learn.adobe.com/wiki/display/coldfusionen/cfcontent)。如果你是CF的新手,我會建議看一下[功能標籤](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec17576-7ffc.html)和[功能分類](http://help.adobe.com/zh_CN/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec1a60c-7ffc.html)首先查看這個問題。 – Leigh

回答

5

是的,有:<cfzip>。在文檔中有一個使用示例,但我會在這裏重新制作,所以我不會因爲基本上說「RTFM」而被打耳光:

<!--- This example shows how to zip the directory "c:\temp" into the ZIP file "e:\work\abc.zip". ---> 
<cfzip file="e:\work\abc.zip" source="c:\temp"> 

<!--- This example shows how to zip all the class files in a directory and add a subdirectory named "classes" to the JAR file entry name. ---> 
<cfzip file="e:\work\util.jar" action="zip" source="c:\src\util\" prefix="classes" filter="*.class"> 

<!---This example shows how to zip all of the log files in the ColdFusion directory and create a subdirectory called exception where zipped files are archived. 
<cfzip file="c:\zipTest\log2.zip" action="zip" source="c:\ColdFusion\" prefix="exception" filter="*.log"> 

<!--- This example shows how to overwrite all of the content of a ZIP file with the entries specified in the source. ---> 
<cfzip file="c:\currentApp.zip" source="c:\myApp\work" overwrite="yes"> 
+3

你在那裏再次進食spoon食人。 –

+0

我知道,對不起。我厭倦了「哦FFS,JFGI」。 –

+0

我認爲在任何人開始寫一行ColdFusion之前,必須將其引入到文檔中。或者更好的是,谷歌。 – fyroc