CFRETURN 到 .CFM 页面

发布于 2024-11-18 21:17:02 字数 5336 浏览 2 评论 0原文

尝试在我的 .cfm 页面上显示该函数创建的 structExcelResult["strUrl"] 。

<cffunction name="getBuyerReport" output="false" access="public" returntype="struct">
<cfargument name="intRegionId" required="yes">
<cfargument name="intBuyerId" required="yes">
<cfargument name="intStage" required="yes">
<cfargument name="strSortField" required="yes">
<cfargument name="strSortDirection" required="yes">
<cfset var structExcelResult = StructNew()>
<cfset var qRead="" />

    <cfquery name="qRead" datasource="#variables.dsn#">
        SELECT CONVERT(varchar,t.RECEIVED_DATE,101) AS [Received Date] 
            , t.REQUISITION_NO AS [Requisition Number]
            , t.REQUISITION_TITLE AS [Requisition Title]
            , t.TECHNICAL_AUTHORITY_NAME AS [Technical Authority]
            , bm.BID_START_DATE AS [Solicitation Date]
            , bm.BID_END_DATE AS [Closing Date]
            , CAST(t.REQ_AMOUNT AS MONEY) AS [Requisition Value]
            , CAST(t.APPROVAL_AMOUNT AS MONEY) AS [Approval Value]
            , t.CURRENT_STAGE AS [Current Stage]
            , CONVERT(varchar,t.ESTIMATED_AWARD_DATE,101) AS [Estimated Award Date]
            , replace(replace(n.NOTE,CHAR(13),''),CHAR(10),'') as [Comments]
            , DATEDIFF(day, t.RECEIVED_DATE, getdate()) AS [Age of Requisition (days)]
            , cb.USER_NAME as [Buyer Name]
            , o.OFFICE_LOCATION_NAME as [Office Location]

        FROM VW__TOMBSTONES__CLIENT_CODES t
            LEFT OUTER JOIN TB__OFFICE_LOCATIONS o 
                ON o.ID = t.OFFICE__ID 
            LEFT OUTER JOIN TB__USERS cb 
                ON t.CURRENT_BUYER__ID = cb.ID
            LEFT OUTER JOIN TB__BID_MANAGEMENTS bm 
                ON bm.TB__TOMBSTONES__ID = t.ID
            LEFT OUTER JOIN TB__REQUISITIONS r 
                ON r.TOMBSTONES__ID = t.ID
            LEFT OUTER JOIN TB__NOTES n 
                ON n.REQUISITION__ID = r.ID
                AND t.CURRENT_STAGE = n.NOTE_TYPE

        WHERE t.CURRENT_STAGE <= 4
            AND n.NOTE_TYPE BETWEEN 1 AND 4
            AND t.REGION__ID = #arguments.intRegionId#
    </cfquery>


    <!--- Create new spreadsheet --->
    <cfset sObj = SpreadsheetNew()>

    <!--- Excel Functions --->
    <cfset countFormula="COUNTA(A8:A20000)">
    <cfset sumFormula="SUM(G2:G2000)">

    <!--- Create header row --->
    <cfset SpreadsheetMergeCells(sObj,1,1,1,2)>
    <cfset SpreadsheetSetCellValue(sObj, "BUYER REGISTER REPORT",1,1)>
    <cfset SpreadsheetFormatRow(sObj, {bold=TRUE, alignment="center"}, 1)>

    <cfset SpreadsheetSetCellValue(sObj, "Report Generated Date:",3,1)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 3,1)>
    <cfset SpreadsheetSetCellValue(sObj, "#ToString(DateFormat(now(), "mmmm d yyyy"))#",3,2 )>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 3,2)>

    <cfset SpreadsheetSetCellValue(sObj, "Number of Requisitions:",4,1)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 4,1)>
    <cfset SpreadsheetSetCellFormula(sObj,countFormula, 4, 2)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 4,2)>

    <cfset SpreadsheetSetCellValue(sObj, "Value of Requisitions:",5,1 )>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 5,1)>
    <cfset SpreadsheetSetCellFormula(sObj,sumFormula, 5, 2)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 5,2)>
    <cfset SpreadsheetFormatCell(sObj, {dataformat="$##,##0.00"}, 5,2)>

    <cfset SpreadsheetAddRow(sObj, "" )>
    <cfset SpreadsheetAddRow(sObj, "RECEIVED DATE,REQUISITION NUMBER,REQUISITION TITLE,TECHNICAL AUTHORITY,SOLICITATION DATE,CLOSING DATE,REQUISITION VALUE,APPROVAL VALUE,CURRENT STAGE,ESTIMATED AWARD DATE,COMMENTS,AGE OF REQUISITION (DAYS),BUYER NAME,OFFICE LOCATION")>
    <cfset SpreadsheetFormatRow(sObj, {bold=TRUE}, 7)>

    <!--- Add orders from query --->
    <cfset SpreadsheetAddRows(sObj, qRead)>
    <cfset SpreadsheetFormatColumns(sObj, {dataformat="$##,##0.00"}, "7-8")>
    <cfset SpreadsheetFormatColumns(sObj, {alignment="center"}, "9-10")>
    <cfset SpreadsheetFormatColumns(sObj, {alignment="center"}, "12-15")>

    <!--- Excel document naming and storing location --->
    <cfset strDir=GetDirectoryFromPath(GetCurrentTemplatePath())&"/../assets/generatedXLS/">
    <cfset strFilePrepend = "-BuyerReport-" />
    <cfset strFileNameStamp = "Galileo" & "#strFilePrepend#" & "#ToString(DateFormat(now(), "yy-mm-dd"))#" & "-#ToString(TimeFormat(now(), "HHmmss"))#" & ".xls"/>

    <cfspreadsheet action="write" 
        filename="#strDir##strFileNameStamp#" 
        name="sObj" 
        overwrite="true" 
        sheetname="Active (Stages 1-4)">

    <cfset structExcelResult["strURL"] = "/web_apps/app/assets/generatedXLS/" & #strFileNameStamp# />
    <cfset structExcelResult["strNoRecordsFoundMsg"] = "" />

<cfreturn structExcelResult>

如何获取该数据 (structExcelResult["strURL"]) 并将其显示在我的 .cfm 页面上?

我是新手,正在阅读 Ben Forta 的书籍...谢谢!

Trying to display structExcelResult["strUrl"] created by the function on my .cfm page.

<cffunction name="getBuyerReport" output="false" access="public" returntype="struct">
<cfargument name="intRegionId" required="yes">
<cfargument name="intBuyerId" required="yes">
<cfargument name="intStage" required="yes">
<cfargument name="strSortField" required="yes">
<cfargument name="strSortDirection" required="yes">
<cfset var structExcelResult = StructNew()>
<cfset var qRead="" />

    <cfquery name="qRead" datasource="#variables.dsn#">
        SELECT CONVERT(varchar,t.RECEIVED_DATE,101) AS [Received Date] 
            , t.REQUISITION_NO AS [Requisition Number]
            , t.REQUISITION_TITLE AS [Requisition Title]
            , t.TECHNICAL_AUTHORITY_NAME AS [Technical Authority]
            , bm.BID_START_DATE AS [Solicitation Date]
            , bm.BID_END_DATE AS [Closing Date]
            , CAST(t.REQ_AMOUNT AS MONEY) AS [Requisition Value]
            , CAST(t.APPROVAL_AMOUNT AS MONEY) AS [Approval Value]
            , t.CURRENT_STAGE AS [Current Stage]
            , CONVERT(varchar,t.ESTIMATED_AWARD_DATE,101) AS [Estimated Award Date]
            , replace(replace(n.NOTE,CHAR(13),''),CHAR(10),'') as [Comments]
            , DATEDIFF(day, t.RECEIVED_DATE, getdate()) AS [Age of Requisition (days)]
            , cb.USER_NAME as [Buyer Name]
            , o.OFFICE_LOCATION_NAME as [Office Location]

        FROM VW__TOMBSTONES__CLIENT_CODES t
            LEFT OUTER JOIN TB__OFFICE_LOCATIONS o 
                ON o.ID = t.OFFICE__ID 
            LEFT OUTER JOIN TB__USERS cb 
                ON t.CURRENT_BUYER__ID = cb.ID
            LEFT OUTER JOIN TB__BID_MANAGEMENTS bm 
                ON bm.TB__TOMBSTONES__ID = t.ID
            LEFT OUTER JOIN TB__REQUISITIONS r 
                ON r.TOMBSTONES__ID = t.ID
            LEFT OUTER JOIN TB__NOTES n 
                ON n.REQUISITION__ID = r.ID
                AND t.CURRENT_STAGE = n.NOTE_TYPE

        WHERE t.CURRENT_STAGE <= 4
            AND n.NOTE_TYPE BETWEEN 1 AND 4
            AND t.REGION__ID = #arguments.intRegionId#
    </cfquery>


    <!--- Create new spreadsheet --->
    <cfset sObj = SpreadsheetNew()>

    <!--- Excel Functions --->
    <cfset countFormula="COUNTA(A8:A20000)">
    <cfset sumFormula="SUM(G2:G2000)">

    <!--- Create header row --->
    <cfset SpreadsheetMergeCells(sObj,1,1,1,2)>
    <cfset SpreadsheetSetCellValue(sObj, "BUYER REGISTER REPORT",1,1)>
    <cfset SpreadsheetFormatRow(sObj, {bold=TRUE, alignment="center"}, 1)>

    <cfset SpreadsheetSetCellValue(sObj, "Report Generated Date:",3,1)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 3,1)>
    <cfset SpreadsheetSetCellValue(sObj, "#ToString(DateFormat(now(), "mmmm d yyyy"))#",3,2 )>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 3,2)>

    <cfset SpreadsheetSetCellValue(sObj, "Number of Requisitions:",4,1)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 4,1)>
    <cfset SpreadsheetSetCellFormula(sObj,countFormula, 4, 2)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 4,2)>

    <cfset SpreadsheetSetCellValue(sObj, "Value of Requisitions:",5,1 )>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="right"}, 5,1)>
    <cfset SpreadsheetSetCellFormula(sObj,sumFormula, 5, 2)>
    <cfset SpreadsheetFormatCell(sObj, {bold=TRUE, alignment="left"}, 5,2)>
    <cfset SpreadsheetFormatCell(sObj, {dataformat="$##,##0.00"}, 5,2)>

    <cfset SpreadsheetAddRow(sObj, "" )>
    <cfset SpreadsheetAddRow(sObj, "RECEIVED DATE,REQUISITION NUMBER,REQUISITION TITLE,TECHNICAL AUTHORITY,SOLICITATION DATE,CLOSING DATE,REQUISITION VALUE,APPROVAL VALUE,CURRENT STAGE,ESTIMATED AWARD DATE,COMMENTS,AGE OF REQUISITION (DAYS),BUYER NAME,OFFICE LOCATION")>
    <cfset SpreadsheetFormatRow(sObj, {bold=TRUE}, 7)>

    <!--- Add orders from query --->
    <cfset SpreadsheetAddRows(sObj, qRead)>
    <cfset SpreadsheetFormatColumns(sObj, {dataformat="$##,##0.00"}, "7-8")>
    <cfset SpreadsheetFormatColumns(sObj, {alignment="center"}, "9-10")>
    <cfset SpreadsheetFormatColumns(sObj, {alignment="center"}, "12-15")>

    <!--- Excel document naming and storing location --->
    <cfset strDir=GetDirectoryFromPath(GetCurrentTemplatePath())&"/../assets/generatedXLS/">
    <cfset strFilePrepend = "-BuyerReport-" />
    <cfset strFileNameStamp = "Galileo" & "#strFilePrepend#" & "#ToString(DateFormat(now(), "yy-mm-dd"))#" & "-#ToString(TimeFormat(now(), "HHmmss"))#" & ".xls"/>

    <cfspreadsheet action="write" 
        filename="#strDir##strFileNameStamp#" 
        name="sObj" 
        overwrite="true" 
        sheetname="Active (Stages 1-4)">

    <cfset structExcelResult["strURL"] = "/web_apps/app/assets/generatedXLS/" & #strFileNameStamp# />
    <cfset structExcelResult["strNoRecordsFoundMsg"] = "" />

<cfreturn structExcelResult>

How do I fetch that data (structExcelResult["strURL"]) and display it on my .cfm page?

I'm new at this and going through Ben Forta books... Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不是你的备胎 2024-11-25 21:17:02

由于您的代码中有一个 cfreturn ,我假设它应该被包装在 cffunction 中。

您可以通过几种不同的方式调用 cffunction。它可能与您所在的同一个 .cfm 页面上:

<cffunction name="sayHello" output="false">
     <cfargument name="username" type="string" required="false" default="Anonymous" />
     <cfreturn "Hello, " & username />
</cffunction>

<cfoutput>#sayHello( 'Charlie' )#</cfoutput>

但是,您的函数更有可能是 ColdFusion 组件 (CFC) 的一部分。要调用属于 CFC 的函数,首先必须实例化 CFC:

<cfset myCFC = createObject( 'component', 'path.to.my.cfc' ) />

现在您可以通过以下方式调用驻留在 CFC 中的任何方法:

<cfoutput>#myCFC.myFunction( 'foo' )#</cfoutput>

回到我的第一个(非常简单)示例,假设 sayHello( ) 函数驻留在位于 /com/Greeting.cfc 的 Greeting.cfc 文件中。

<cfset greeting = createObject( 'component', 'com.greeting' ) />
<cfoutput>#greeting.sayHello( 'Charlie' )#</cfoutput>

您可以使用任何您喜欢的名称。它不必是myCFCgreeting。它只是一个代表组件挂钩的变量。

希望有帮助。

Since you have a cfreturn in your code, I'll assume that was meant to have been wrapped in cffunction.

You can call a cffunction a couple of different ways. It could be on the same .cfm page that you're on:

<cffunction name="sayHello" output="false">
     <cfargument name="username" type="string" required="false" default="Anonymous" />
     <cfreturn "Hello, " & username />
</cffunction>

<cfoutput>#sayHello( 'Charlie' )#</cfoutput>

However, it's more likely that your function is part of a ColdFusion Component (CFC). To call a function that's part of a CFC, you first have to instantiate the CFC:

<cfset myCFC = createObject( 'component', 'path.to.my.cfc' ) />

Now you can call any method that resides in the CFC via:

<cfoutput>#myCFC.myFunction( 'foo' )#</cfoutput>

Going back to my first (very simple) example, let's say the sayHello() function resided in the Greeting.cfc file that was at /com/Greeting.cfc.

<cfset greeting = createObject( 'component', 'com.greeting' ) />
<cfoutput>#greeting.sayHello( 'Charlie' )#</cfoutput>

You can use anything you'd like for the name. It doesn't have to be myCFC or greeting. It's just a variable that represents a hook into your component.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文