我有一个生成多个电子表格对象的cfm页面,现在如果我尝试发送文件进行下载,只会将下一个生成的电子表格文件作为下载文件发送。
有没有办法将这些文件写入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();
}
现在,通过这种方式,我只获得了生成的最后一个电子表格。有没有办法让所有生成的电子表格一个接一个或者可能是拉链?
答案 0 :(得分: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">