3 Replies Latest reply on Feb 13, 2008 8:57 AM by jayshiro

    Exporting datagrid rows into Excel

    appana71
      Hi
      Could any body tell me how we can export datagrid rows into excel without using Clipboard.
        • 1. Re: Exporting datagrid rows into Excel
          ntsiii Level 3
          You can use LocalConnection, with a swf in the excel form.

          Google this, there are several other options.

          Tracy
          • 2. Exporting datagrid rows into Excel
            michael_ramirez44 Level 1
            This function generates an HTML version of my datagrid
            private function exportToExcel():void
            {
            var now:Date = new Date();
            var col:DataGridColumn;
            var clip:String = "";

            clip += "<html><body>"
            clip += "<strong>" + reportName.text + "</strong><br>";
            clip += "<strong>" + now.toString() + "</strong><br>";
            clip += "";
            clip += "<table width='100%' border='1'><tr>";
            for each( col in dgResults.columns )
            {
            if( col.visible )
            {
            clip += "<td bgcolor='#666666'<strong><font color='#FFFFFF'>" + col.headerText + "</font></strong></td>";
            }
            }
            clip += "</tr>";
            var colorRow:Boolean = false;
            for each( var item:Object in results )
            {
            var total:Number = 0;
            for each( var x:* in ltColumns)
            {
            if( !isNaN(item[x]) )
            {
            total += Number(item[x]);
            }
            }
            item["Total"] = numFormatter.format(total);

            if( colorRow )
            {
            clip += "<tr bgcolor='#CCCCCC'>";
            colorRow = false;
            }
            else
            {
            colorRow = true;
            clip += "<tr>";
            }
            for each( col in dgResults.columns )
            {
            if( col.visible )
            {
            clip += "<td>";
            if( item[col.dataField] != undefined )
            {
            clip += item[col.dataField];
            }
            clip += "</td>";
            }
            }
            clip += "</tr>";
            }
            clip += "</table></html></body>";

            Using HTTPService post excel data to JSP,ASP, or PHP page to generate excel document
            generateExcelDocument.send({excelData: clip});
            }

            private function postResultHandler(event:ResultEvent):void
            {
            HTTPService returns with the URL of the generated excel document
            var request:URLRequest = new URLRequest(StringUtil.trim(event.result.toString()));
            Force Flex to open excel document.
            navigateToURL(request,"_self");
            }
            • 3. Re: Exporting datagrid rows into Excel
              jayshiro

              hi michael_ramirez44,

              can you please provide the full mxml file of your example as some of the variable and method natures are kind of confusing. like this:
              generateExcelDocument.send({excelData: clip});

              i would really like to fully understand how your sample works.
              thanks.