我在Microsoft Windows Server2008 R2数据中心-SP1上使用SQL Server2012数据源运行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来完成吗?或者我被锁定在每个工作表上只使用一个查询?
发布于 2013-04-19 07:57:29
可以用cfspreadsheet实现吗?
不是的。write操作仅接受单个查询。但是,您始终可以将工作表读取到变量中。然后使用SpreadSheetAddRow将其他值附加到该工作表。
另外,您还可以直接从变量中流式传输电子表格。请注意,这可能会占用更多的资源。
<cfheader name="Content-Disposition" value="attachment; filename=someFile.xls" />
<cfcontent type="application/vnd.msexcel"
variable="#spreadSheetReadBinary(yourSpreadSheetObject)#" /> 发布于 2013-04-19 10:30:54
你没有被锁定在任何东西里。有许多方法可以将数据放入电子表格中。利给了您一个链接,指向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)>不要纠结于这个例子的粗俗之处。关键是,如果你不限制自己,你可以用电子表格函数做很多事情。
https://stackoverflow.com/questions/16094738
复制相似问题