Apr 15, 2016

Excel file import

static void ExcelImport()
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    FilenameOpen                    filename;
    LogisticsAddressCountryRegionTranslation    _LogisticsAddressCountryRegionTranslation;
    int row = 1; // if the excel has the header

    str 3         _ConCode;
    str 200       _KORLong;
    str 200       _KORShot;

    int           totNoOfLeaves;

    ;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    filename  = "C:\\Users\\nux.kim\\Desktop\\국가코드작업_20140220_박병욱 책임.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++;

        _ConCode           = cells.item(row,1).value().bStr();
        _KORLong           = cells.item(row,5).value().bStr();
        _KORShot           = cells.item(row,6).value().bStr();

        select forUpdate _LogisticsAddressCountryRegionTranslation
        where _LogisticsAddressCountryRegionTranslation.LanguageId == 'ko-kr'
        && _LogisticsAddressCountryRegionTranslation.CountryRegionId == _ConCode;
        if (_LogisticsAddressCountryRegionTranslation)
        {
            _LogisticsAddressCountryRegionTranslation.LongName = _KORLong;
            _LogisticsAddressCountryRegionTranslation.ShortName = _KORShot;
            _LogisticsAddressCountryRegionTranslation.update();
        }


        // 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
    workbooks.close();
    application.quit();
}

No comments:

Post a Comment