下面的代码将生成带有两个明显错误的文件:
- SpreadSheetSetColumnWidth 在第二个选项卡上的 21 行后似乎停止工作
- 图像未出现在第二个选项卡上
希望这只是一个新手错误,而不是日期格式问题。任何帮助或建设性的批评来修复/改进都将受到极大的欢迎。
<!--- We cannot directly reference the image --->
<cfimage source="img/A2LA_Logo.jpg" name="A2LA_Logo">
<!--- We need an absolute path, so get the current directory path. --->
<cfset theFile=GetDirectoryFromPath(GetCurrentTemplatePath()) & "Final_Report.xlsx">
<cfscript>
/*********************************************************************** Page 1 ***********************************************************************/
//Create a new Excel spreadsheet object - SpreadsheetNew("Tab name", "yes=2007+ no=2003");
Tab1 = SpreadsheetNew("Final Report Page 1","yes");
SpreadSheetSetRowHeight(Tab1,1,45);
SpreadsheetSetCellValue(Tab1,"Final Test Report",1,1); SpreadsheetMergeCells(Tab1,1,1,1,10);
SpreadsheetAddImage(Tab1, A2LA_Logo,"jpg","1,12,2,20");
SpreadsheetSetCellValue(Tab1,"Confidential",1,21); SpreadsheetMergeCells(Tab1,1,1,21,30);
</cfscript>
<cfscript>
/*********************************************************************** Page 2 ***********************************************************************/
//Create a new Excel spreadsheet object - SpreadsheetNew("Tab name", "yes=2007+ no=2003");
Tab2 = SpreadsheetNew("Final Report Page 2","yes");
SpreadSheetSetRowHeight(Tab2,1,45);
SpreadsheetSetCellValue(Tab2,"Final Test Report",1,1); SpreadsheetMergeCells(Tab2,1,1,1,10);
SpreadsheetAddImage(Tab1, A2LA_Logo,"jpg","1,12,2,20");
SpreadsheetSetCellValue(Tab2,"Confidential",1,21); SpreadsheetMergeCells(Tab2,1,1,21,30);
</cfscript>
<!--- There must be a better way --->
<cfscript>
for(index=1; index LTE 30; index++) {SpreadSheetSetColumnWidth(Tab1,index,3);}
for(index=1; index LTE 30; index++) {SpreadSheetSetColumnWidth(Tab2,index,3);}
</cfscript>
<!--- Write the spreadsheet to a file, replacing any existing file, then append the other tabs. --->
<cfspreadsheet action="write" filename="#theFile#" name="Tab1" overwrite=true>
<cfspreadsheet action="update" filename="#theFile#" name="Tab2">
<!--- Needs to be at the bottom --->
<cfheader name="Content-disposition" value="attachment;filename=Final_Report.xlsx">
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" file="#theFile#">
<!--- Clean up your mess after it is served to the browser --->
<cffile action="delete" file="#theFile#">