>Faye,
>
>
>
>>
>> I am trying to export the data which is an arrayCollection in Flex to
>> Excel. I followed this article,
>> http://viconflex.blogspot.com/2007/02/export-data-from-flex-app-using.html,
>> and got all the components working. Now the last step is to make the data
>> (arrayCollection) available in #arguments.data#, I guess.
>>
>
>I'll need a little more explanation. Your original example was a ColdFusion
>query. Now you say it's data coming from Flex.
>
>Is it being created from scratch in Flex? Didn't it originate as server-side
>data?
>
>ColdFusion is just Java under the hood, and you'll find you'll use many of
>the same patterns.
>
>If you can walk us through the process - basically, how did Flex get the
>data, how was it manipulated, and such - what it's returning - we can
>probably help. It would also help to know what's supposed to happen with the
>spreadsheet. Is it to be displayed, just saved, or what?
>
>As much detail as you can provide on the steps in the process, please.
>
>
>-- 
>Thanks,
>
>Tom
>
>Tom McNeer
>MediumCool
>http://www.mediumcool.com
>1735 Johnson Road NE
>Atlanta, GA 30306
>404.589.0560


Hi Tom,

Let me give it one more try and be thorough. Please find all the files used 
below for this issue. The data is retrieved and Excel will open. The problem 
is, Excel is opened without any data.

Code starts here
======================

I will provide all my code here:

Flex datagrid page:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml";>
        <mx:Script>
                <![CDATA[
                        
                        import mx.collections.ArrayCollection;
                        import mx.controls.Alert;
                        import mx.rpc.events.FaultEvent;
                        import mx.rpc.events.ResultEvent;  
                        
                        [Bindable] private var roResults:ArrayCollection;
                        
                        private function buttonHandler():void {
                                roWildcard.getAllAsStruct();
                        }
                        
                        private function resultHandler( event:ResultEvent 
):void {
                                roResults = new ArrayCollection( event.result 
as Array );
                        }
                        
                        private function faultHandler( event:FaultEvent ):void {
                                Alert.show( event.toString(), "Remote Object 
Fault" );
                        }
                        
                        private function test():void{   
                                exportManager.exportToExcel("" +        "" +    
    
                                        "The application has successfully 
exported this file    " +      

  
                                        "Eventually the actual data will be 
passed into this function" + 

       
                                        "");
                        }
                        private function login_result(event:ResultEvent):void{  
 

                                if(event.result == true){        
                                        var request:URLRequest = new 
URLRequest("getExcelFile.cfm");     

   
                                        flash.net.navigateToURL(request, 
"_self");   
                                }
                        }
                                
                        private function serverFault( event:FaultEvent ):void {
                                Alert.show( event.toString(), "Remote Object 
Fault" );
                        }
                        

                
                ]]>
        </mx:Script>
        
        <!--                                                    
        types of returns you can have from ColdFusion -> Flex,                  
                        
        getAllAsStruct creates an array of structures to pass back              
                                
        with a special '__type__' struct key indicating to Flex what the type 
is.                               

                
        -->                                                     

        <mx:RemoteObject id="roWildcard"
                         destination="ColdFusion"
                         
source="DeptApps.Statistics.Faye.stardust.cfc.CustomerGateway"
                                         showBusyCursor="true"
                         result="resultHandler(event)"
                         fault="faultHandler(event)"/>  
        <!--                                                    
        Make sure the Flex cffunction exportToExcel is available on the 
coldfustion component                   

                        
        (DeptApps.Statistics.Faye.stardust.cfc.)Export.cfc                      
                        
        -->                                                     
        
        <mx:RemoteObject id="exportManager"       
                                         destination="ColdFusion"       
                                         
source="DeptApps.Statistics.Faye.stardust.cfc.Export"                  

        
                                         showBusyCursor="true">     
                                        <mx:method name="exportToExcel" 
result="login_result(event)" 

fault="serverFault(event)" />  
        </mx:RemoteObject>      

        
        <mx:Panel title="{this.label}" width="100%" height="100%">
                <mx:HBox>
                        <mx:Button label="Call RemoteObject" 
click="buttonHandler()"/>  
                        <mx:Button label="Export" click="test()"/>      
                </mx:HBox>

                <mx:DataGrid id="dg" dataProvider="{roResults}" width="100%" 
height="100%"/>

        </mx:Panel>
        
        
</mx:Canvas>



CustomerGateway.cfc

<cfcomponent output="false">

        <!--- Populating an array from a query, an array of CFML structures --->
        <cffunction name="getAllAsStruct" output="false" access="remote" 
returntype="array">
                <cfset var qRead="">
                <cfset var aRead = []/>
                <cfset var sRead = {}/>
                
                <cfquery name="qRead" datasource="#application.dsn#">
                        select *
                        from sav_customer
                </cfquery>
                
                <cfloop query="qRead">
                        <cfset sRead = {}/>
                        <cfset sRead["__type__"] = "stardust.cfc.Contact"/>
                        <cfset sRead["id_rssd"] = qRead.id_rssd/>
                        <cfset sRead["ctct_id"] = qRead.ctct_id/>
                        <cfset sRead["ser_id"] = qRead.ser_id/>
                        <cfset sRead["inst_nm"] = qRead.inst_nm/>               
        
                        <cfset sRead["ctct_fst_nm"] = qRead.ctct_fst_nm/>
                        <cfset sRead["ctct_lst_nm"] = qRead.ctct_lst_nm/>
                        <cfset sRead["updt_dt"] = qRead.updt_dt/>
                        <cfset arrayAppend(aRead, sRead)/>
                </cfloop>

                <cfreturn aRead>        

        </cffunction>

</cfcomponent>



Export.cfc

<cfcomponent> 
        
        <cffunction name="exportToExcel" access="remote" returntype="boolean" 
output="true">   
        <cfargument name="data" type="string" required="yes" default="" />  
        <cfset session.exportData= #arguments.data#> 
        <cflog text="data to be exported: #session.exportData#"/>   
        <cfreturn true> 
        </cffunction>   
        
</cfcomponent>


getExcelFile.cfm
<cfsetting enablecfoutputonly="true" showdebugoutput="No">
        <cfheader name="Content-Disposition" value="attachment; 
filename=export.xls"/>
        <cfcontent type="application/vnd.ms-excel" reset="true"/>
        <cfscript> 
                WriteOutput(session.exportData);
        </cfscript>
<cfexit />

======================
Code ends here

I need to know how to set session.exportData to the return from CustomerGateway 
return method. Do I need to create another function?


Thank you very much for your time.

Faye Larson
Dallas 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:340583
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to