在导出到 Excel 之前如何更改 cfquery 结果的值?

How can I change the value of a cfquery result before exporting to Excel?

我已经有了将 CFQuery 导出到 Excel 文件的工作代码。但是,我似乎无法弄清楚如何在将结果写入电子表格之前更改结果。 RSVP 列的值是 Y 或 N。当我导出数据时,我希望单元格显示接受或拒绝。

有办法吗?谢谢。

这是我当前的代码:

<cfscript>
    // Get data from a query
    Query=QueryExecute("SELECT NAME, RSVP FROM TABLE",[],{datasource="DBASE"});

    // Create a spreadsheet object with sheetname
    spObj=spreadsheetNew("Query",true);

    // Add rows with data from query result. The data start from row 1, col 1. The spreadsheet will have column names.
    SpreadSheetAddRow(spObj, 'NAME,RSVP');

    //Make the header bold
    SpreadsheetformatRow(spObj,{bold=true},1);

    //Create the Spreadsheet
    SpreadSheetAddRows(spObj,Query,2,1,true,["STRING"],false);
</cfscript>

将此添加为答案。在 SQL 中,您需要使用 CASE 语句 return "Accept" 或 "Decline"(或您喜欢的任何文本)。

在你的情况下,它可能看起来很像这样:

SELECT
  [Name],
  CASE WHEN [RSVP] LIKE 'Y' THEN 'ACCEPT' ELSE 'DECLINE' END AS Response
FROM
  [TableName]