package myvocal.utils { import flash.events.Event; import flash.filesystem.*; import mx.collections.ListCollectionView; import mx.controls.Alert; import mx.controls.DataGrid; import mx.controls.dataGridClasses.DataGridColumn; /** * Export to excel (XML spread sheet) */ public class XMLSpreadsheet { private static const header:String = " " + "" + "" + "" + "" + "" + ""; private static const trailer:String = "
"; private static var xmlss:String; /** * convert to string of XMLSS */ public static function convertDataGridToXMLSS(_grid:DataGrid):String { if(_grid.dataProvider.length <=0) { return ""; } //column var table_str:String = ""; for(var c:int=0 ; c<_grid.columns.length ; c++) { var _col:DataGridColumn = _grid.columns[c]; table_str += "" + _col.headerText + "" } table_str += ""; //Loop through the records in the dataprovider and //insert the column information into the table var _dp:ListCollectionView = _grid.dataProvider as ListCollectionView; for(var i:int=0 ; i<_dp.length ; i++) { if(_dp.getItemAt(i) != null) { table_str += ""; for(var j:int=0 ; j<_grid.columns.length ; j++) { //Check to see if the user specified a labelfunction which we must //use instead of the dataField var func:Function = (_grid.columns[j] as DataGridColumn).labelFunction; var cellData:String = ""; if(func != null) { cellData = func(_dp.getItemAt(i), _grid.columns[j]) //table_str += "" + + ""; } else { cellData = _dp.getItemAt(i)[(_grid.columns[j] as DataGridColumn).dataField]; //table_str += "" + _dp.getItemAt(i)[(_grid.columns[j] as DataGridColumn).dataField] + ""; } table_str += "" + cellData + ""; } table_str += ""; } } return header + table_str + trailer; } } }