flex datagrid 내보내기 csv

4354 단어 datagrid
public  function exportToCSV(dataGrid:DataGrid):void

            { 

                

                var dataProviderCollection:ArrayCollection = dataGrid.dataProvider as ArrayCollection;

                var rowCount:int = dataProviderCollection.length; 

                var ExcelStr:Array = [];// 

                var columnsFiledText:Array = new Array();// 

                var columnsFiledName:Array = new Array();// 

                for each(var column:GridColumn in dataGrid.columns)

                {

                    // Datagrid 

                    columnsFiledText.push(column.headerText.toString());

                    // DataGrid 

                    columnsFiledName.push(column.dataField.toString());

                } 

                // 

                ExcelStr.push(columnsFiledText.join(",").toString());    

                

                for(var r:int = 0;r<rowCount;r++)

                {

                    var rowData:Object = dataProviderCollection.getItemAt(r);    

                    var csvRow:Array =new Array();//     

                    for each(var col:String in columnsFiledName)

                    {  

                        var text:String;

                        text = rowData[col];

                        }

                        csvRow.push(text);// 

                    } 

                    // 

                    ExcelStr.push(csvRow.join(",").toString());

                }            

                var bytes:ByteArray = new ByteArray();

                var fileReference:FileReference = new FileReference();

                bytes.writeMultiByte(ExcelStr.join("\r
"
),"gb2312"); fileReference.save(bytes,"test.csv"); }

좋은 웹페이지 즐겨찾기