Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:58:02+00:00 2026-06-10T02:58:02+00:00

I created a datagrid and also created some text box and a submit button

  • 0

I created a datagrid and also created some text box and a submit button outside the datagrid.. if we entered some data’s into the text box and then click the submit button the data’s are stored into the datagrid.. i want to export these data from the data grid is export into excel.How it possiple?How can i create a excel sheet and how it connect with my datagrid?
My code is given below

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import com.as3xls.xls.Sheet;

            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.effects.easing.Exponential;
            import mx.events.FlexEvent;


            [Bindable]
            public var dgItems_client:ArrayCollection = new ArrayCollection();
            public var dgItems_admin:ArrayCollection = new ArrayCollection();
            public var temp_client:Object = new Object();
            public var temp_admin:Object = new Object();
            private var fileRef:FileReference=new FileReference;
            private var sheet:Sheet;
            //          public var imagegrid:Image;
            private function tabChange():void
            {
                errorAdmin.visible=false;
                errorClient.visible=false;
                if(gh.selectedChild.name=='clientTab')
                {
                    details.dataProvider=dgItems_client;
                    arrayName.headerText="Client_Name";
                }
                else
                {
                    details.dataProvider=dgItems_admin;
                    arrayName.headerText="Admin_Name";
                }
            }
            private function submitClick():void
            {
                if(name_client.text!="" && address_client.text!="" && phone_client.text!="")
                {

                    temp_client = ({Name:name_client.text, Address:address_client.text,Phone_Number:phone_client.text});
                    dgItems_client.addItem(temp_client);
                    name_client.text="";
                    address_client.text="";
                    phone_client.text="";
                    clientClick();
                    errorClient.visible=false;
                }
                else
                {
                    errorClient.visible=true;
                }
                if(name_admin.text!=""&&address_admin.text!=""&&phone_admin.text!="")
                {
                    temp_admin = ({Name:name_admin.text, Address:address_admin.text,Phone_Number:phone_admin.text});
                    dgItems_admin.addItem(temp_admin);
                    name_admin.text="";
                    address_admin.text="";
                    phone_admin.text="";
                    errorAdmin.visible=false;
                }
                else
                {
                    errorAdmin.visible=true;
                }

            }
            private function clientClick():void
            {

                details.dataProvider=dgItems_client;
                arrayName.headerText="Client_Name";
            }
            private function adminClick():void
            {

                details.dataProvider=dgItems_admin;
                arrayName.headerText="Admin_Name";
            }
            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                fileRef.addEventListener(Event.SELECT,fileSelected);

            }
            private function fileSelected():void
            {

            }
            private function executeExport():void
            {
                 sheet=new Sheet;
//               var dataProviderCollection:ArrayCollection;
                var rowCount:int=details.columnsLength;
                Alert.show(rowCount.toString());
            }

        ]]>
    </fx:Script>
    <mx:TabNavigator x="27" y="11" width="455" height="376" id="gh" change="tabChange()" backgroundColor="#A4B6E9">
        <s:NavigatorContent width="100%" height="100%" label="Client" id="clientTab">
            <s:Label x="10" y="30" width="52" height="25" text="Name:"/>
            <s:Label x="10" y="127" width="52" height="28" text="Address:"/>
            <s:TextInput id="name_client" x="69" y="18" width="188" height="37" restrict="a-zA-Z"/>
            <s:TextArea id="address_client" x="70" y="70" height="126"/>
            <s:Label x="10" y="230" width="84" height="32" text="Phone:"/>
            <s:TextInput id="phone_client" x="70" y="218" width="188" height="30" restrict="0-9" maxChars="10"/>
            <s:Button x="100" y="291" height="28" label="Submit"  click="submitClick()"/>           
            <s:Label id="errorClient" x="59" y="270" width="171" height="27" text="please fill the blank fields" color="red" visible="false"/>
        </s:NavigatorContent>
        <s:NavigatorContent width="100%" height="100%" label="Admin" id="adminTab" >
            <s:Label x="23" y="48" width="52" height="25" text="Name:"/>
            <s:Label x="26" y="148" width="52" height="28" text="Address:"/>
            <s:TextInput id="name_admin" x="105" y="33" width="188" height="37"/>
            <s:TextArea id="address_admin" x="105" y="93" height="126"/>
            <s:Label x="26" y="257" width="84" height="32" text="Phone:"/>
            <s:TextInput id="phone_admin" x="104" y="246" width="188" height="30" restrict="0-9" maxChars="10"/>
            <s:Button x="137" y="305" height="28" label="Submit" click="submitClick()"/>
            <s:Label id="errorAdmin" x="100" y="286" width="171" height="17" color="red" fontSize="14"
                     text="please fill the blank fields" visible="false"/>
            <s:Button x="335" y="60" height="34" label="Admin Details" click="adminClick()"/>
            <s:Button x="335" y="180" height="34" label="Client Details" click="clientClick()"/>

        </s:NavigatorContent>
    </mx:TabNavigator>
    <s:TitleWindow x="521" y="84" width="377" height="234">
        <s:DataGrid x="0" y="0" width="375" height="163" borderVisible="true" id="details">
            <s:columns>
                <s:ArrayList>
                    <s:GridColumn dataField="Name" id="arrayName"></s:GridColumn>
                    <s:GridColumn dataField="Address" headerText="Address"></s:GridColumn>
                    <s:GridColumn dataField="Phone_Number" headerText="Phone_Number"></s:GridColumn>
                </s:ArrayList>
            </s:columns>
        </s:DataGrid>
        <s:Button x="139" y="167" height="28" label="Export" click="executeExport()"/>
    </s:TitleWindow>
</s:Application>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:58:04+00:00Added an answer on June 10, 2026 at 2:58 am

    ok…
    You can try below code: –

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
                   >
        <fx:Declarations>
            <!-- Place non-visual elements (e.g., services, value objects) here -->
        </fx:Declarations>
        <fx:Script>
            <![CDATA[
                import com.as3xls.xls.Sheet;
    
                import mx.collections.ArrayCollection;
                import mx.controls.Alert;
                import mx.effects.easing.Exponential;
                import mx.events.FlexEvent;
    
    
                [Bindable]
                public var dgItems_client:ArrayCollection = new ArrayCollection();
                public var dgItems_admin:ArrayCollection = new ArrayCollection();
                public var temp_client:Object = new Object();
                public var temp_admin:Object = new Object();
    
                private function tabChange():void
                {
                    errorAdmin.visible=false;
                    errorClient.visible=false;
                    if(gh.selectedChild.name=='clientTab')
                    {
                        details.dataProvider=dgItems_client;
                        arrayName.headerText="Client_Name";
                    }
                    else
                    {
                        details.dataProvider=dgItems_admin;
                        arrayName.headerText="Admin_Name";
                    }
                }
                private function submitClick():void
                {
                    if(gh.selectedIndex == 0)
                    {
                        if(name_client.text!="" && address_client.text!="" && phone_client.text!="")
                        {
    
                            temp_client = ({Name:name_client.text, Address:address_client.text,Phone_Number:phone_client.text});
                            dgItems_client.addItem(temp_client);
                            name_client.text="";
                            address_client.text="";
                            phone_client.text="";
                            clientClick();
                            errorClient.visible=false;
                        }
                        else
                        {
                            errorClient.visible=true;
                        }
                    }else
                    {
                        if(name_admin.text!="" && address_admin.text!="" && phone_admin.text!="")
                        {
                            temp_admin = ({Name:name_admin.text, Address:address_admin.text,Phone_Number:phone_admin.text});
                            dgItems_admin.addItem(temp_admin);
                            name_admin.text="";
                            address_admin.text="";
                            phone_admin.text="";
                            errorAdmin.visible=false;
                        }
                        else
                        {
                            errorAdmin.visible=true;
                        }
                    }
                }
    
                private function clientClick():void
                {
    
                    details.dataProvider=dgItems_client;
                    arrayName.headerText="Client_Name";
                }
                private function adminClick():void
                {
    
                    details.dataProvider=dgItems_admin;
                    arrayName.headerText="Admin_Name";
                }
    
                private function executeExport():void
                {
                    ExcelExporterUtil.dataGridExporter(this.details, "prueba_excel.xls");
                }
    
            ]]>
        </fx:Script>
        <mx:TabNavigator x="27" y="11" width="455" height="376" id="gh" change="tabChange()" backgroundColor="#A4B6E9">
            <s:NavigatorContent width="100%" height="100%" label="Client" id="clientTab">
                <s:Label x="10" y="30" width="52" height="25" text="Name:"/>
                <s:Label x="10" y="127" width="52" height="28" text="Address:"/>
                <s:TextInput id="name_client" x="69" y="18" width="188" height="37" restrict="a-zA-Z"/>
                <s:TextArea id="address_client" x="70" y="70" height="126"/>
                <s:Label x="10" y="230" width="84" height="32" text="Phone:"/>
                <s:TextInput id="phone_client" x="70" y="218" width="188" height="30" restrict="0-9" maxChars="10"/>
                <s:Button x="100" y="291" height="28" label="Submit"  click="submitClick()"/>           
                <s:Label id="errorClient" x="59" y="270" width="171" height="27" text="please fill the blank fields" color="red" visible="false"/>
            </s:NavigatorContent>
            <s:NavigatorContent width="100%" height="100%" label="Admin" id="adminTab" >
                <s:Label x="23" y="48" width="52" height="25" text="Name:"/>
                <s:Label x="26" y="148" width="52" height="28" text="Address:"/>
                <s:TextInput id="name_admin" x="105" y="33" width="188" height="37"/>
                <s:TextArea id="address_admin" x="105" y="93" height="126"/>
                <s:Label x="26" y="257" width="84" height="32" text="Phone:"/>
                <s:TextInput id="phone_admin" x="104" y="246" width="188" height="30" restrict="0-9" maxChars="10"/>
                <s:Button x="137" y="305" height="28" label="Submit" click="submitClick()"/>
                <s:Label id="errorAdmin" x="100" y="286" width="171" height="17" color="red" fontSize="14"
                         text="please fill the blank fields" visible="false"/>
                <s:Button x="335" y="60" height="34" label="Admin Details" click="adminClick()"/>
                <s:Button x="335" y="180" height="34" label="Client Details" click="clientClick()"/>
    
            </s:NavigatorContent>
        </mx:TabNavigator>
        <s:TitleWindow x="521" y="84" width="377" height="234">
            <mx:DataGrid x="0" y="0" width="375" height="163" borderVisible="true" id="details">
                <mx:columns>
                    <mx:DataGridColumn dataField="Name" id="arrayName"></mx:DataGridColumn>
                    <mx:DataGridColumn dataField="Address" headerText="Address"></mx:DataGridColumn>
                    <mx:DataGridColumn dataField="Phone_Number" headerText="Phone_Number"></mx:DataGridColumn>
                </mx:columns>
            </mx:DataGrid>
            <s:Button x="139" y="167" height="28" label="Export" click="executeExport()"/>
        </s:TitleWindow>
    </s:Application>
    

    ExcelExporterUtil.as

    package 
    {
        import com.as3xls.xls.ExcelFile;
        import com.as3xls.xls.Sheet;
    
        import flash.errors.IllegalOperationError;
        import flash.net.FileReference;
        import flash.utils.ByteArray;
    
        import mx.collections.ArrayCollection;
        import mx.collections.ICollectionView;
        import mx.collections.IViewCursor;
        import mx.collections.XMLListCollection;
        import mx.controls.DataGrid;
    
        public class ExcelExporterUtil
        {
            public function ExcelExporterUtil()
            {
                throw new IllegalOperationError("Class \"ExcelExporterUtil\" is static. You can't instance this");
            }
    
            static public function dataGridExporter(dg:DataGrid, defaultName:String):void
            {
                if (dg == null || dg.dataProvider == null || defaultName == null || defaultName == "")
                    return;
    
                var cols:Number = 0;
                var colsValues:Array = [];
                var cantCols:Number = dg.columnCount;
                var fieldT:String;
                var headerT:String;
    
                // armo el listado de headers y variables para cada columna
                for ( ; cols < cantCols; cols++)
                {
                    headerT = (dg.columns[cols] as Object).headerText
                    fieldT = (dg.columns[cols] as Object).dataField;
                    if ( fieldT == null || fieldT == "" || headerT == null || headerT == "")
                        continue; 
                    colsValues.push({
                        header:headerT,
                        value:fieldT
                    });
                }
    
                if ( colsValues.length == 0 )
                    return;
    
                ExcelExporterUtil.export(dg.dataProvider, colsValues, defaultName);
            }
    
            static public function chartExporter(chart:ByteArray, defautlName:String):void
            {
                if(chart)
                {
                    var sheet:Sheet = new Sheet();
                    sheet.resize(1, 1);
                    sheet.setCell(0, 0, "Chart Data");
    
                    sheet.setCell(0,0,chart);
    
                    var xls:ExcelFile = new ExcelFile();
                    xls.sheets.addItem(sheet);
                    var bytes:ByteArray = xls.saveToByteArray();
    
                    var fr:FileReference = new FileReference();
                    fr.save(bytes, defautlName);    
                }
            }
    
            static public function export(obj:Object, colsValues:Array, defautlName:String):void
            {
                var _dp:ICollectionView = ExcelExporterUtil.getDataProviderCollection(obj);
                if ( _dp == null )
                    return;
    
                var rows:Number = 0;
                var cols:Number = 0;
                var cantCols:Number = colsValues.length;
                var sheet:Sheet = new Sheet();
                sheet.resize(_dp.length, colsValues.length);
    
                for ( ; cols < cantCols; cols++)
                {
                    sheet.setCell(rows, cols, colsValues[cols].header);
                }
    
                cols = 0;
                rows++;
                var cursor:IViewCursor = _dp.createCursor();
                while ( !cursor.afterLast )
                {
                    for (cols = 0 ; cols < cantCols; cols++)
                    {
                        if ( (cursor.current as Object).hasOwnProperty(colsValues[cols].value) )
                            sheet.setCell(rows, cols, (cursor.current as Object));
                    }
    
                    rows++;
                    cursor.moveNext();
                }
    
                var xls:ExcelFile = new ExcelFile();
                xls.sheets.addItem(sheet);
                var bytes:ByteArray = xls.saveToByteArray();
    
                var fr:FileReference = new FileReference();
                fr.save(bytes, defautlName);
            }
    
            static private function getDataProviderCollection(obj:Object):ICollectionView
            {
                if ( (obj is Number && isNaN(obj as Number)) || (!(obj is Number) && obj == null))
                {
                    return null;
                }
                else if ( obj is ICollectionView )
                {
                    return obj as ICollectionView;
                }
                else if ( obj is Array )
                {
                    return new ArrayCollection(obj as Array);
                }
                else if ( obj is XMLList )
                {
                    return new XMLListCollection(obj as XMLList);
                }
                else if ( obj is XML )
                {
                    var col:XMLListCollection = new XMLListCollection();
                    col.addItem(obj);
                    return col;
                }
                else if ( obj is Object )
                {
                    return new ArrayCollection([obj]);
                }
                else
                {
                    return null;
                }
            }
        }
    }
    

    Hope may help you….
    Note: – i am using ExcelExporterUtil.as from one of the post.. not created by me..

    Or Other way, can refer below post: –
    http://cookbooks.adobe.com/post_Import_Export_data_in_out_of_a_Datagrid_in_Flex-17223.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a Column button in datagrid using this code <Columns> <asp:ButtonColumn Text=Resend ButtonType=PushButton
I have created simple DataGrid with 4 columns, which go outside the bounds of
I have a WPF DataGrid with some data. You can add rows through a
I'm using DOJO v1.7.2. I've created Datagrid in Dialog widget declaratively. I've included needed
I have the following scenario, I want to create a DataGrid and then populate
I'm trying to create a dynamic datagrid in Flex. The data is coming back
I'm trying to create a DOJO DataGrid populated using a dojo.data.ItemFileReadStore with very simple
Hey guys, I have an application that I want to display some data from
I'm reading data from XML files into a strong typed DataSet . The data
My app as it initiates it populates a DataGrid with data retrieved from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.