creating multiple sheets using Coldfusion SpreadsheetWrite and cfscript

后端 未结 1 1251
独厮守ぢ
独厮守ぢ 2021-01-14 06:04

I\'d like to create a single excel file with two sheets using CF9, SpreadsheetWrite and cfscript. Something like:

var data= spreadsheetNew( \'data\' );
var          


        
相关标签:
1条回答
  • 2021-01-14 06:37

    Yes, it is not very clear from the documentation. SpreadsheetNew creates a Workbook with a single worksheet. To add additional sheets, use the SpreadSheetCreateSheet function. Before you can manipulate the new sheet, it must be made active with SpreadSheetSetActiveSheet. Here is a quick example of creating a workbook with two sheets:

    <cfscript>
        // Create new workbook with one worksheet. 
        // By default this worksheet is active
        Workbook = SpreadsheetNew("Sheet1");
        // Add data to the currently active sheet
        SpreadSheetAddRow(Workbook, "Apples");
        SpreadSheetAddRow(Workbook, "Oranges");
    
    
        //Add second worksheet, and make it active
        SpreadSheetCreateSheet(Workbook, "Sheet2");
        // Add data to the second worksheet
        SpreadSheetSetActiveSheet(Workbook, "Sheet2");
        SpreadSheetAddRow(Workbook, "Music");
        SpreadSheetAddRow(Workbook, "Books");
    
        //Finally, save it to a file
        SpreadSheetWrite(Workbook, "c:/path/to/yourFile.xls", true);
    </cfscript>
    

    Side note, I would not recommend using <cfspreadsheet action="update"> anyway. Last I recall it was a bit buggy.

    0 讨论(0)
提交回复
热议问题