Export from custTable to Excel file in axapta

To Export Records from custTable to Excel  file in  axapta You can try following code.

 static void ExportingFields4mCustTable(Args _args)  
 {  
 CustTable CustTableLocal;  
 SysExcelApplication excelApp;  
 SysExcelWorkSheet excelWorksheet;  
 SysExcelRange excelRange;  
 SysExcelCells excelCells;  
 SysExcelCell excelCell;  
 ComVariant cellValue;  
 Int i=1;  
 ;  
 excelApp = SysExcelApplication::construct();  
 cellValue = new ComVariant() ;  
 excelApp.workbooks().add();  
 excelWorksheet = excelApp.worksheets().itemFromNum( 1 );  
 excelCells = excelWorksheet.cells();  
 while select * from CustTableLocal  
 {  
 excelCells.item(i+4,4).value(cellValue.bStr(CustTableLocal.AccountNum));  
 excelCells.item(i+4,5).value(cellValue.bStr(CustTableLocal.Name));  
 i++;  
 }  
 excelApp.visible(true);  
 }