使用Coldfusion SpreadsheetWrite和cfscript创建多个工作表 [英] creating multiple sheets using Coldfusion SpreadsheetWrite and cfscript
问题描述
我想使用CF9,SpreadsheetWrite和cfscript创建一个具有两个表的excel文件。像:
I'd like to create a single excel file with two sheets using CF9, SpreadsheetWrite and cfscript. Something like:
var data= spreadsheetNew( 'data' );
var key= spreadsheetNew( 'key');
spreadsheetAddRow( data, dataInfo );
spreadsheetAddRow( key, keyInfo );
spreadsheetWrite( data, filePath );
spreadsheetWrite( key, filePath );
我没有找到解释如何在一个文件中合并多个工作表的文档。这是我找到的。
I don't find documentation that explains how to combine multiple sheets in one file. Here's what I find.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0-7b585809122c5a12c54-7fff.html
它说可以'将多个工作表写入单个文件',但是这是否意味着一次多个工作表不清楚。
It states that one can 'Write multiple sheets to a single file.' but whether that means more than one sheet at a time is not clear. You can accomplish this using tags but I need to use cfscript.
<cfspreadsheet action="update" filename = "filePath" sheetname = "key" >
如何使用cfscript编写上述基于标记的调用?
How does one write the above tag-based call using cfscript?
推荐答案
是的,从文档中不是很清楚。 SpreadsheetNew使用单个工作表创建一个工作簿。要添加其他工作表,请使用 SpreadSheetCreateSheet 功能。在您可以操作新工作表之前,必须先使用 SpreadSheetSetActiveSheet 。下面是使用两个工作表创建工作簿的简单示例:
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>
注意,我不建议使用< cfspreadsheet action =update >
。 最后我记得它有点儿车。
Side note, I would not recommend using <cfspreadsheet action="update">
anyway. Last I recall it was a bit buggy.
这篇关于使用Coldfusion SpreadsheetWrite和cfscript创建多个工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!