I'm using CFScript to create and save a spreadsheet. However, SpreadsheetWrite
isn't producing a file.
<cfscript>
...
...
...
spreadsheetWrite(sObj, yourSheet, "yes");
</cfscript>
It does not produce an error, but there's no file either. If I remove spreadsh开发者_StackOverflow社区eetwrite from the cfscript tag and use:
<cfspreadsheet action = "write" fileName = "#yourSheet#" name = "sObj">
... I get the file just fine.
Was this not the intended use of SpreadsheetWrite()
? Also, is it possible to produce a spreadsheet directly to the browser like cfdocument
, or do I have to save the file first?
(Update: With relative paths it may be saving the file somewhere you are not expecting. Use an absolute path so there are no guessing games.)
This works for me using absolute paths.
<cfscript>
yourSheet = "c:/myFile.xls";
sObj = SpreadSheetNew("MySheet");
SpreadsheetAddRow(sObj,"Foo,Bar",1,1);
SpreadSheetWrite(sObj, yourSheet, true);
WriteOutput("Exists?= "& FileExists(yourSheet));
</cfscript>
To display the spreadsheet in the browser, use SpreadSheetReadBinary and cfcontent. Obviously use the appropriate mime type and file extension.
<cfheader name="Content-Disposition" value="attachment; filename=SomeFile.xls" />
<cfcontent type="application/vnd.msexcel" variable="#SpreadSheetReadBinary(yourSpreadSheetObject)#" />
精彩评论