05 November 2020

How to get data and time from Excel using X++

Below is code snippet can be used to get the date and time from excel.

 // Convert into str from excel cell value

    str COMVariant2Str(COMVariant cv, int decimals = 0, int characters = 0, int separator1 = 0, int _separator2 = 0)

    {

        switch (_cv.variantType())

        {

            case (COMVariantType::VT_BSTR):

            return _cv.bStr();


            case (COMVariantType::VT_R4):

            return num2str(_cv.float(),_characters,_decimals,_separator1,_separator2);


            case (COMVariantType::VT_R8):

            return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);


            case (COMVariantType::VT_DECIMAL):

            return num2str(_cv.decimal(),_characters,_decimals,_separator1,_separator2);


            case (COMVariantType::VT_DATE):

            //return date2str(_cv.date(),123,2,1,2,1,4);

            return date2str(_cv.date(),213,2,1,2,1,4)+" "+time2str(_cv.time(),TimeSeparator::Colon, TimeSeparator::Colon);


            case (COMVariantType::VT_EMPTY):

            return '';


            default:

            throw error(strfmt('@SYS26908', _cv.variantType()));

        }

        return '';

    }

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension->...