Satishpethani92 / as3xls

Automatically exported from code.google.com/p/as3xls
0 stars 0 forks source link

Zeros instead of blanks? #60

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Can anybody tell me why the records with blanks on the datagrid show as zeros 
instead of blanks? Thanks

    {

                    CursorManager.setBusyCursor();

                    sheet = new Sheet();
                    var dataProviderCollection:ArrayCollection = excelgrid.dataProvider as ArrayCollection;
                    var rowCount:int = dataProviderCollection.length;
                    sheet.resize(rowCount + 1,excelgrid.columnCount);
                    var columns:Array = excelgrid.columns;
                    columns.splice(0, 1) // to delete the first column which is the number of each record , because this field has no datafield, the excel
                        //function does not work if we include it in the table like it is included now
                    var i:int = 0;

                    for each (var field:DataGridColumn in columns)

                    {  

                        fields.push(field.dataField.toString());

                        sheet.setCell(0,i,field.dataField.toString());
                        i++;

                    }

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

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

                        /*insert record starting from row no 2 else
                        headers will be overwritten*/
                        insertRecordInSheet(r+1,sheet,record);

                    }

                    var xls:ExcelFile = new ExcelFile();
                    xls.sheets.addItem(sheet);

                    CursorManager.removeBusyCursor();

                    var bytes: ByteArray = xls.saveToByteArray();
                    var fr:FileReference = new FileReference();
                    fr.save(bytes,"DirectoryofForestProductsIndustries.xls");
                }

                else 
                {
                    Alert.show("Make sure your search produces any results before using this tool");
                    CursorManager.removeBusyCursor();
                }

            }

            private function insertRecordInSheet(row:int,sheet:Sheet,record:Object):void
            {
                var colCount:int = excelgrid.columnCount;
                for(var c:int; c < colCount; c++)
                {
                    var i:int = 0;
                    for each(var field:String in fields)
                    {
                        for each (var value:String in record)
                        {
                            if (record[field].toString() == value)
                                sheet.setCell(row,i,value);
                        }
                        i++;
                    }

                }

            }

Original issue reported on code.google.com by ionarawi...@gmail.com on 3 Dec 2012 at 3:52