Friday, April 16, 2010

Reading the SalesId from excel to post the SalesOrder using X++

Reading SalesId from Excel-sheet and then Posting it

static void ReadingSalesIdfromExcel(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    SalesPosting    salesposting;   //Wrote my own class having a method Post to post a Sales Order.
    int row;
    SalesId salesId;
    #define.Filename('D:\\SalesOrders.xlsx')
    ;
    salesposting    =   new Salesposting();
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    try
    {
    workbooks.open(#Filename);
    }
    catch (Exception::Error)
    {
    throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    do
    {
    row++;
    salesId = cells.item(row, 1).value().bStr();
    salesposting.post(salesId);// Posting the Sales order with the help of SalesId from excel
    type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    application.quit();
}

No comments:

Post a Comment