1

I want to get data from xls file with help of as3xls.

private var file:FileReference = new FileReference();
private var sheet:Sheet;
private var loadedFile:ByteArray;

private function sendLogistImport():void {  
    file.addEventListener(Event.SELECT, onFileSelect);
    file.browse();
    file.addEventListener(Event.COMPLETE, 
        function (e:Event):void { 
            loadedFile = e.currentTarget.data as ByteArray;
            var excelFile:ExcelFile = new ExcelFile();
            excelFile.loadFromByteArray(loadedFile);                
            sheet = excelFile.sheets[0]; 
            Alert.show(sheet.getCell(1,0).value);
        }
    );
}
private function onFileSelect(e:Event):void {
    file.load(); 
}

But I get this error at the excelFile.loadFromByteArray(loadedFile);:

Error: Error #2030: End of file was encountered.
    at flash.utils::ByteArray/readUTFBytes()
    at com.as3xls.xls::ExcelFile/boundsheet()[/Users/manuelwudka-robles/Documents/Flex Builder 3/as3xls/com/as3xls/xls/ExcelFile.as:633]
    at Function/http://adobe.com/AS3/2006/builtin::call()
    at com.as3xls.xls::ExcelFile/loadFromByteArray()[/Users/manuelwudka-robles/Documents/Flex Builder 3/as3xls/com/as3xls/xls/ExcelFile.as:309]
    at Function/<anonymous>()[D:\logist.as:244]

This is my xls file's screenshot :

enter image description here

Here is my xls file: http://www.filedropper.com/template_1

Please tell me, where is my mistake?

ndm
  • 59,784
  • 9
  • 71
  • 110
Valentyn Grygoriev
  • 463
  • 10
  • 29
  • This is not a `.xls` file, it's a screenshot. Anyways, the error is pretty clear about what's happening, the code is trying to read towards the end of the file, so the options here are that it's a bug in the library, that your files structure is not supported (the library was last updated nearly 6 years ago), or that your files structure is incorrect. – ndm Oct 30 '13 at 13:25
  • I think everything is ok with my xls file. I created it in old Excel 2003 format. I added link above in main text to xls file, so you can look at him. – Valentyn Grygoriev Oct 30 '13 at 15:22

1 Answers1

1

I've tested it with various XLS formats, and it can't read any of them. Judging from the comments, the support for the various XLS formats is rather bad.

Try it with different XLS formats, maybe you find one that works, other than that I'm afraid I can't help you, fixing the problem in the library is a monstrous task, and I wouldn't touch it with a ten-foot pole: http://www.openoffice.org/sc/excelfileformat.pdf

Also check out some of the forks around the net, like for example https://github.com/djw/as3xls, they may have some fixes implemented that get you going.

And if nothing work for you, then I'd suggest to look for another library, and/or even use a totally different file format (like CSV) if that is an option.

ndm
  • 59,784
  • 9
  • 71
  • 110