开发者

CFRETURN to .CFM page

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"] = "" /开发者_如何学C>

<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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜