0

I want to upload excel file and show the content of uploaded excel file data grid. Everything is going well. But when i convert the the content in the form of byteArray in excel sheet format with the help of loadFromByteArray() function then system is giving me error as "Cannot access a property or method of a null object reference".
Here is my code to upload excel content:

protected function browseExcelFile(event:MouseEvent):void  
{   
 excFileRef = new FileReference();  
 excFileRef.addEventListener(Event.SELECT, onSelect);  
 excFileRef.addEventListener(Event.COMPLETE, onComplete); 
 var fileFilter:FileFilter = new FileFilter("Excel (.xls)", "*.xls");  
 excFileRef.browse([fileFilter]);  
} 

private function onSelect(event:Event):void {                               
 excelFileName.text = excFileRef.name;  
 excFileRef.load();  
}   

private function onComplete(event:Event):void {                                 
excelFileName.text = excFileRef.name;  
exceldataInByte = new ByteArray();    
exceldataInByte = event.currentTarget.data;  
if(exceldataInByte.length > 0){  
 var excObj:ExcelFile = new ExcelFile();  
 excObj.loadFromByteArray(exceldataInByte); /* this line give error */  
 var sheet:Sheet = excObj.sheets[0];  
}           
}

I dont know why this error occuring, i have searched on many sites but everywhere everyone posted the same way as i have done to upload excel but my code gives me error.
Please tell me why this error occur?

splash
  • 13,037
  • 1
  • 44
  • 67
user2393886
  • 832
  • 2
  • 8
  • 17
  • I suppose you are using **as3xls**? What version is your excel file? as3xls _supports reading text, numbers, formulas, and dates from Excel version 2.x-2003_. Most likely it could be a version conflict. – splash Sep 03 '13 at 12:16
  • I edited my response below, basically you cannot use a spreadsheet with > 2 columns. – squarephoenix Sep 03 '13 at 14:13

1 Answers1

0

EDIT: After viewing this preview (http://activetuts.s3.amazonaws.com/tuts/169_as3xls/1/preview.html) I realized that this excel import tool only works with spreadsheets who only have 2 columns of data, regardless of how many columns your datagrid has. After trying to load an .xls file of only two columns into my own test app, it is working as expected.

I believe I recreated your error.

Here is the line that threw the error:

excObj.loadFromByteArray(exceldataInByte); /* this line give error */  

Here is the error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.as3xls.xls::ExcelFile/dimensions()[/...com/as3xls/xls/ExcelFile.as:619]
at Function/http://adobe.com/AS3/2006/builtin::call()
at com.as3xls.xls::ExcelFile/loadFromByteArray()[/...com/as3xls/xls/ExcelFile.as:309]
at stackoverflow/onComplete()[C:\...\src\stackoverflow.mxml:47]

Here is the line which is throwing the error in the swc (line 619): https://code.google.com/p/as3xls/source/browse/trunk/src/com/as3xls/xls/ExcelFile.as#619

I suggest you checkout the source code into your workspace from here (https://code.google.com/p/as3xls/source/checkout), and debug to find what is broken.

squarephoenix
  • 1,003
  • 7
  • 7