Saturday, 11 July 2015

static void productDim(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;
    Table1            Table;
    ;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    filename  = "C:\\Users\\axservice2012\\Desktop\\DataImport.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.EcoResProductDimensionGroupName  = cells.item(row,2).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