向cfspreadsheet输出添加文本/额外查询

我在Microsoft Windows Server 2008 R2数据中心上使用SQL Server 2012数据源运行Coldfusion 10。

我在页面上有一个cfspreadsheet标签,如下所示:

<cfinvoke component="assetdata" method="getAllNames" searchString ="#url.searchoption#" returnVariable="result"> <cfspreadsheet action = "write" query="result" filename="#filename#" overwrite="true"> <div>Your spreadsheet is ready. You may download it <a href="search_results.xls">here</a>.</div</div> 

我想要做的是除了输出查询到电子表格是像这样的查询结果添加到它的底部:

正在使用的电脑总数:110

要更换的电脑总数:62

已经被更换的电脑总数:8

在绘制信息的页面上每个都有自己的select语句。 这可以用cfspreadsheet来完成吗? 还是我locking在每张纸上只使用一个查询?

这可以用cfspreadsheet来完成吗?

不。 write操作只接受一个查询。 但是,您始终可以将表单读入一个variables。 然后使用SpreadSheetAddRow将附加值附加到该表。

另外,您也可以直接从一个variables中传输电子表格。 请注意,这可能是更多的资源密集型。

 <cfheader name="Content-Disposition" value="attachment; filename=someFile.xls" /> <cfcontent type="application/vnd.msexcel" variable="#spreadSheetReadBinary(yourSpreadSheetObject)#" /> 

你没有被锁住任何东西。 有很多方法可以将数据放入电子表格中。 Leigh为您提供了一个ColdFusion提供的可用函数的链接。

大多数(如果不是所有可用于将数据输出到网页的方法)都可用于将数据输出到电子表格。 下面是一些示例代码,用数据填充工作表的第1列。 稍后其他查询会填充标题行和使用情况数据

 <cfloop query="DrugsByCategory"> <cfscript> SpreadsheetAddRow(Workbook, "", RowNumber, 1); SpreadSheetSetCellValue(Workbook, DrugsByCategory.Item[DrugsByCategory.currentrow], RowNumber, 1); if (DrugsByCategory.type[DrugsByCategory.currentrow] == "Category"){ SpreadsheetFormatCell(Workbook, CategoryFormat, RowNumber, 1); StartOfDrugRange = RowNumber + 1; } else if (DrugsByCategory.type[DrugsByCategory.currentrow] == "Summary"){ SpreadsheetFormatCell(Workbook, SummaryFormat, RowNumber, 1); EndOfDrugRange = RowNumber - 1; } </cfscript> <!--- get data for each drug, and then the summary ---> <cfif DrugsByCategory.type[DrugsByCategory.currentrow] is "Category"> code for this condition <cfelseif DrugsByCategory.type[DrugsByCategory.currentrow] is "Drug"> Code for this condition <cfelseif DrugsByCategory.type[DrugsByCategory.currentrow] is "Summary"> code for this condition </cfif> <cfset RowNumber ++> </cfloop> <cfset SpreadSheetAddFreezePane(Workbook, 1, 3)> 

不要挂在这个例子的不雅之上。 重点是,如果你不限制自己,你可以用电子表格function做很多事情。