Skip to main content

Posts

Showing posts with the label Excel tips and trick

Import data from axapta table to excel through code

SysExcelApplication ExcelApplication; SysExcelWorkBooks ExcelWorkBooks; SysExcelWorkBook ExcelWorkBook; SysExcelWorkSheets ExcelWorkSheets; SysExcelWorkSheet ExcelWorkSheet; SysExcelRange ExcelRange; CustTable custTable; int row=1; ExcelApplication = SysExcelApplication ::construct( ); ExcelApplication. visible(true) ; ExcelWorkBooks = ExcelApplication. workbooks( ); ExcelWorkBook = ExcelWorkBooks. add(); ExcelWorkSheets = ExcelWorkBook. worksheets( ); ExcelWorkSheet = ExcelWorkSheets. itemFromNum( 1); ExcelWorkSheet. cells().item( row,1).value( 'Account num'); ExcelWorkSheet. cells().item( row,2).value( 'Name'); row++; while select custTable where custtable.AccountNum like 'c-000*' { ExcelWorkSheet. cells().item( row,1).value( custTable. AccountNum) ; ExcelWorkSheet. cells().item( row,2).value( custTable. Name); row++; } ExcelApplication. finalize( );

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); }