</code><?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init()" creationComplete="createhtml()"> <fx:Declarations> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; private var _arrColl:ArrayCollection = new ArrayCollection([{status:"Sen",Age:"12"}, {status:"Gan",Age:"12"},{status:"Kum",Age:"12"},{status:"Chan",Age:"12"}]); [Bindable] private var _headerName:String=""; [Bindable] private var _tabelContent:String = "";; private var _htmlString:String = "<html>"+ "<head>" + "<title>Tested ArrayCollection</title>" + "</head>" + "<body>" + "<br/>" + "<br/>" + "<table border="+"1" +">"+ "<thead>"+ "<tr>"+"##_headerName##"+ "</tr>"+ "</thead>"+ "<tbody>"+"##_tabelContent##"+ "</tbody>"+ "</table>"+ "</body>"+ "</html>"; [Bindable] private var gBytes:ByteArray = new ByteArray(); // get the Detail From the Array Collection private function init() :void { var arr:Array = ["status","Age"]; for( var i:int = 0;i < arr.length;i++) { _headerName += "<th bgcolor="+"#736F6E"+">"+arr[i]+"</th>"; } for( var j:int = 0;j < _arrColl.length;j++) { _tabelContent += "<tr><td>"+_arrColl[j].status+"</td><td>"+_arrColl[j].Age+"</td></tr>" } } // replace the String ... and saved as private function createhtml() :void { var cContents:String = _htmlString; cContents = cContents.replace( "##_headerName##",_headerName); cContents = cContents.replace( "##_tabelContent##", _tabelContent ); gBytes.writeMultiByte( cContents, "utf-8" ); var cFile:File = new File(); cFile = File.desktopDirectory.resolvePath("Task.html" ); cFile.addEventListener( Event.SELECT, onSelectSave ); cFile.browseForSave( "report" ); } /** * Function used to save the Html File .. **/ private function onSelectSave( event:Event ):void { var cFile:File = event.target as File; var cFS:FileStream = new FileStream(); cFile.removeEventListener( Event.SELECT, onSelectSave ); cFS.open( cFile, FileMode.WRITE ); cFS.writeBytes( gBytes ); cFS.close(); gBytes.length = 0; } ]]> </fx:Script> </s:WindowedApplication> <code>
Notes: If u want to save the File as Excel change the Extension as .html to .xls …
You can use FlexADGToHtmlExportUtil.
Util for export Flex Advanced Data Grid to HTML table.
https://github.com/Igor912/FlexADGToHtmlExportUtil.git