arikdan / as3xls

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

2044 Error #39

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I try to save a xls file as the same name that exist file name.
2. I saw player error.
3.

What is the expected output? What do you see instead?
Error #2044: 처리되지 않은 IOErrorEvent입니다. text=Error #2038: 
파일 I/O 오류입니다.
    at ExcelDownload/exportToExcel()[D:\project\hanjun\flex\SampleFlex4\src\excel\ExcelDownload.mxml:134]
    at ExcelDownload/___ExcelDownload_Button2_click()[D:\project\hanjun\flex\SampleFlex4\src\excel\ExcelDownload.mxml:166]

What version of the product are you using? On what operating system?
flex sdk 4.1, player 10.1

Please provide any additional information below.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import com.as3xls.xls.Cell;
            import mx.collections.ArrayCollection;

            import com.as3xls.xls.Sheet;
            import com.as3xls.xls.ExcelFile;
            import mx.controls.dataGridClasses.DataGridColumn; 

            private var fileReference:FileReference;
            private var sheet:Sheet;

            [Bindable]
            private var fields:Array = new Array();  
            private var ItemDGDataProvider:ArrayCollection = new ArrayCollection([
                {name:"Item1",value:"21",qty:"3",cost:"12.21"},
                {name:"Item2",value:"20",qty:"4",cost:"12.22"},
                {name:"Item3",value:"22",qty:"5",cost:"12.23"},
                {name:"Item4",value:"23",qty:"2",cost:"12.24"}
            ]);

            [Bindable]
            private var rebateDGDataProvider:ArrayCollection = new ArrayCollection();

            private function browseAndUpload():void
            {
                fileReference = new FileReference();
                fileReference.addEventListener(Event.SELECT,fileReference_Select);
                fileReference.addEventListener(Event.CANCEL,fileReference_Cancel);
                fileReference.browse();
            }
            private function fileReference_Select(event:Event):void
            {
                fileReference.addEventListener(Event.COMPLETE,fileReference_Complete);
                fileReference.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
                fileReference.load();   
            }
            private function fileReference_Cancel(event:Event):void
            {
                fileReference = null;
            }
            private function onLoadError():void
            {
                /*body not implemented*/
            }
            private function fileReference_Complete(event:Event):void
            {
                var fileData:ByteArray  = fileReference.data;
                var excelFile:ExcelFile = new ExcelFile();
                var noOfRows:int;
                var noOfColumns:int;
                if(fileData!=null && fileData.length > 0){
                    excelFile.loadFromByteArray(fileData);
                    if(excelFile.sheets.length>0)
                    {
                        var sheet:Sheet = excelFile.sheets[0];
                        if(sheet!=null)
                        {
                            noOfRows=sheet.rows;
                            noOfColumns = sheet.cols;
                            for(var row:int = 0; row<noOfRows;row++)
                            {
                                var cellObject:Object ={};
                                for(var col:int=0;col<noOfColumns;col++)
                                {
                                    var cell:Cell = new Cell();
                                    var cellValue:String = new String();
                                    cell = sheet.getCell(row,col);
                                    if(cell!=null)
                                    {
                                        cellValue =(cell.value).toString();
                                        addProperty(cellObject,col,cellValue);
                                    }
                                }// inner for loop ends

                                rebateDGDataProvider.addItem(cellObject);
                            } //for loop ends
                        } //if sheet 
                    }
                } //if filedata
                rebateScheduleDG.includeInLayout = true;
                rebateScheduleDG.visible = true;
                fileReference = null;
            }
            private function addProperty(cellObject:Object,index:int,cellValue:String):void
            {
                if(index == 0)
                    cellObject.cost = cellValue;
                else if(index == 1)
                    cellObject.name = cellValue;
                else if(index == 2)
                    cellObject.qty = cellValue;
                else if(index == 3)
                    cellObject.value = cellValue;
            }

            private function exportToExcel():void
            {
                sheet = new Sheet();
                var dataProviderCollection:ArrayCollection = rebateByItemDG.dataProvider as ArrayCollection;
                var rowCount:int =  dataProviderCollection.length;
                sheet.resize(rowCount+4,10);
                sheet.setCell(0,0,"Item Name");
                sheet.setCell(0,1,"Item Cost");
                sheet.setCell(0,2,"Item Qty");
                sheet.setCell(0,3,"Item Price");
                var columns:Array = rebateByItemDG.columns;  
                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+2,sheet,record);
                }
                var xls:ExcelFile = new ExcelFile();
                xls.sheets.addItem(sheet);

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

            private function insertRecordInSheet(row:int,sheet:Sheet, record:Object):void
            {  
                var colCount:int = rebateByItemDG.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);  
                        } // if  
                        i++;  
                    } // for record  
                } // for fields  
            } // for colCount  

        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <s:Button label="Browse" click="browseAndUpload()"/>
    <mx:DataGrid id="rebateScheduleDG" 
                 dataProvider="{rebateDGDataProvider}" width="100%"/>
    <mx:DataGrid id="rebateByItemDG" 
                 dataProvider="{ItemDGDataProvider}" width="100%" editable="true"/>
    <s:Button label="Export To Excel" click="exportToExcel();"/>

</s:Application>

Original issue reported on code.google.com by bryan.wi...@gmail.com on 16 Dec 2010 at 1:21

GoogleCodeExporter commented 9 years ago
for UTF-8 i have the probleme to use special caractr like "é à ..."

Original comment by khalidla...@gmail.com on 30 Oct 2013 at 5:03