Saturday, 11 July 2015

ItemMasterImport_Job1

static void ItemMasterImport_Job1(Args _args)
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    FilenameOpen                    filename;
    int row = 1; // if the excel has the header
    TransDate     empJoiningDate;
    real          salary;
    str           empId;
    int           totNoOfLeaves;
    ItemId        itemId;
    Name            name;
    Table2            Table;
    ;
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    filename  = "C:\\Users\\axservice2012\\Desktop\\Book2.xlsx"; // file path
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File not found");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    //Iterate through cells and get the values
    do
    {
    //Incrementing the row line to next Row
    row++;
    Table.ItemId       = cells.item(row,1).value().bStr();
    Table.ItemName     = cells.item(row,2).value().bStr();
    Table.OldItem      = cells.item(row,3).value().bStr();
    Table.Size         = cells.item(row,4).value().bStr();
    Table.Color        = cells.item(row,5).value().bStr();
    Table.OldItemName  = cells.item(row,6).value().bStr();
    Table.Prefix       = cells.item(row,7).value().bStr();
    Table.insert();
    //info(strFmt("Empl Id:- %1 , DOJ :- %2 , Salary :- %3 ,  TotNoLeaves :-   %4",empId,empJoiningDate,salary,totNoOfLeaves));
    // Loads the next row into the variant type and validating that its is empty or not
    type = cells.item(row+1, 1).value().variantType();
    }
    while (type != COMVariantType::VT_EMPTY);
    // quits the application
    application.quit();
}

No comments:

Post a Comment