2014-01-27 44 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