Import data from Excel file to AX using X++ in AX 2012

Posted by Alvin You
2013.10.23 00:19 Dynamics AX

Excel 파일을 Import 받아 AX에 구성되어 있는 Standard or Developed Table에 값을 집어 넣는 로직입니다. Delphi나 VB, Powerbuilder 개발을 해 보셨던 분들에겐 익숙한 코딩일 듯 싶습니다.


static void ReqAmount(Args _args)
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    Name name;
    FileName filename;
    ReqAmount reqAmount;
    int row;
    str _reqOrderNo;
    int _reqAmount;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    filename = "D:\\ReqAmount.xlsx";
    catch (Exception::Error)
        throw error("File cannot be opened.");
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1); //첫번째 Sheet
    cells = worksheet.cells();
        _reqOrderNo = any2str(cells.item(row, 1).value().toString());
        _reqAmount = cells.item(row, 2).value().int();

        reqAmount.ReqOrderNo = _reqOrderNo;
        reqAmount.ReqAmount = _reqAmount;

        type = cells.item(row+1, 1).value().variantType();
    } while (type != COMVariantType::VT_EMPTY);

'Dynamics AX' 카테고리의 다른 글

Dynamics AX Useful Links  (0) 2013.10.25
Minimizing risk, maximizing returns  (0) 2013.10.25
Import data from Excel file to AX using X++ in AX 2012  (0) 2013.10.23
RecId란?  (0) 2013.10.20
훌륭한 Dynamics AX Project Manager에 필요한 자질  (0) 2013.10.16
SAP vs Oracle vs AX  (0) 2013.10.13
이 댓글을 비밀 댓글로