0

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 spreadsheetwrite 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?

Leigh
  • 28,765
  • 10
  • 55
  • 103
genericHCU
  • 4,394
  • 2
  • 22
  • 34
  • Are you using absolute file paths? – Leigh Jul 07 '11 at 18:11
  • Hi Leigh. No, relative path. at one point I got a "cannot find path specified" error but once that was corrected I just don't get a file. I even just tried the file name to dump it into the current directory but, nothing. – genericHCU Jul 07 '11 at 18:23
  • With relative paths it may be saving the file somewhere you are not expecting. Use an absolute path instead. Use ExpandPath() if needed. – Leigh Jul 07 '11 at 18:29

1 Answers1

2

(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)#" />    
Leigh
  • 28,765
  • 10
  • 55
  • 103