Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can I treat VT_DATE ?

How can I treat VT_DATE ?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontestingtoolshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I have an Automation excel class with follow method :

    CString CXLAutomation::GetCellValueCString(int nColumn, int nRow)
    {
    CString szValue =_T("");
    if(NULL == m_pdispWorksheet)return szValue;

    VARIANTARG vargRng, vargValue;
    ClearAllArgs();
    AddArgumentDouble(NULL, 0, nColumn);
    AddArgumentDouble(NULL, 0, nRow);
    if(! ExlInvoke(m\_pdispWorksheet, L"Cells",&vargRng, DISPATCH\_PROPERTYGET, DISP\_FREEARGS))return szValue;
    
    if(! ExlInvoke(vargRng.pdispVal, L"Value", &vargValue, DISPATCH\_PROPERTYGET, 0))return szValue;
    
    VARTYPE Type = vargValue.vt;
    switch(Type)
    {
    case VT\_UI1:
    	{
    		TCHAR nChr = vargValue.bVal;
    		szValue = nChr;
    	}
    	break;
    case VT\_I4:
    	{
    		long nVal = vargValue.lVal;
    		szValue.Format("%i", nVal);
    	}
    	break;
    case VT\_R4:
    	{
    		float fVal = vargValue.fltVal;
    		szValue.Format("%f", fVal);
    	}
    	break;
    case VT\_R8:
    	{
    		double dVal = vargValue.dblVal;
    		szValue.Format("%f", dVal);
    	}
    	break;
    case VT\_BSTR:
    	{
    		BSTR b = vargValue.bstrVal;
    		szValue = b;
    	}
    	break;
    case VT\_BYREF|VT\_UI1:
    	{
    		//Not tested
    		unsigned char\* pChr = vargValue.pbVal;
    		szValue = (TCHAR)\*pChr;
    	}
    	break;
    case VT\_BYREF|VT\_BSTR:
    	{
    		//Not tested
    		BSTR\* pb = vargValue.pbstrVal;
    		szValue = \*pb;
    	}
    	break;
    case 0:
    	{
    		//Empty
    		szValue = \_T("");
    	}
    	break;
    }
    

    // ReleaseVariant(&vargRng);
    // ReleaseVariant(&vargValue);

    return szValue;
    

    }

    but haven't VT_DATE and VT_DATE | VT_BYREF case ... can you give me an help hand ? I can show you what I try , but didn't working ... Thank you . P.S. I search to google , but I didn't find something appropiate ... :(

    C T 2 Replies Last reply
    0
    • _ _Flaviu

      I have an Automation excel class with follow method :

      CString CXLAutomation::GetCellValueCString(int nColumn, int nRow)
      {
      CString szValue =_T("");
      if(NULL == m_pdispWorksheet)return szValue;

      VARIANTARG vargRng, vargValue;
      ClearAllArgs();
      AddArgumentDouble(NULL, 0, nColumn);
      AddArgumentDouble(NULL, 0, nRow);
      if(! ExlInvoke(m\_pdispWorksheet, L"Cells",&vargRng, DISPATCH\_PROPERTYGET, DISP\_FREEARGS))return szValue;
      
      if(! ExlInvoke(vargRng.pdispVal, L"Value", &vargValue, DISPATCH\_PROPERTYGET, 0))return szValue;
      
      VARTYPE Type = vargValue.vt;
      switch(Type)
      {
      case VT\_UI1:
      	{
      		TCHAR nChr = vargValue.bVal;
      		szValue = nChr;
      	}
      	break;
      case VT\_I4:
      	{
      		long nVal = vargValue.lVal;
      		szValue.Format("%i", nVal);
      	}
      	break;
      case VT\_R4:
      	{
      		float fVal = vargValue.fltVal;
      		szValue.Format("%f", fVal);
      	}
      	break;
      case VT\_R8:
      	{
      		double dVal = vargValue.dblVal;
      		szValue.Format("%f", dVal);
      	}
      	break;
      case VT\_BSTR:
      	{
      		BSTR b = vargValue.bstrVal;
      		szValue = b;
      	}
      	break;
      case VT\_BYREF|VT\_UI1:
      	{
      		//Not tested
      		unsigned char\* pChr = vargValue.pbVal;
      		szValue = (TCHAR)\*pChr;
      	}
      	break;
      case VT\_BYREF|VT\_BSTR:
      	{
      		//Not tested
      		BSTR\* pb = vargValue.pbstrVal;
      		szValue = \*pb;
      	}
      	break;
      case 0:
      	{
      		//Empty
      		szValue = \_T("");
      	}
      	break;
      }
      

      // ReleaseVariant(&vargRng);
      // ReleaseVariant(&vargValue);

      return szValue;
      

      }

      but haven't VT_DATE and VT_DATE | VT_BYREF case ... can you give me an help hand ? I can show you what I try , but didn't working ... Thank you . P.S. I search to google , but I didn't find something appropiate ... :(

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Initialize (i.e. construct) a COleDateTime object with vargValue.date and then use COleDateTime's Format method, see COleDateTime documentation[^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      _ 1 Reply Last reply
      0
      • C CPallini

        Initialize (i.e. construct) a COleDateTime object with vargValue.date and then use COleDateTime's Format method, see COleDateTime documentation[^]. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        _ Offline
        _ Offline
        _Flaviu
        wrote on last edited by
        #3

        Ok , I will try , but how VT_DATE | VT_BYREF case ?

        C 1 Reply Last reply
        0
        • _ _Flaviu

          Ok , I will try , but how VT_DATE | VT_BYREF case ?

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          What about:

          COleDateTime dt(*(vargValue.pdate));

          ?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          _ 1 Reply Last reply
          0
          • C CPallini

            What about:

            COleDateTime dt(*(vargValue.pdate));

            ?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
            [My articles]

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            Great ! Now does function well. Thanks a lot !!! I don't know how to test last case (VT_DATE | VT_BYREF).

            1 Reply Last reply
            0
            • _ _Flaviu

              I have an Automation excel class with follow method :

              CString CXLAutomation::GetCellValueCString(int nColumn, int nRow)
              {
              CString szValue =_T("");
              if(NULL == m_pdispWorksheet)return szValue;

              VARIANTARG vargRng, vargValue;
              ClearAllArgs();
              AddArgumentDouble(NULL, 0, nColumn);
              AddArgumentDouble(NULL, 0, nRow);
              if(! ExlInvoke(m\_pdispWorksheet, L"Cells",&vargRng, DISPATCH\_PROPERTYGET, DISP\_FREEARGS))return szValue;
              
              if(! ExlInvoke(vargRng.pdispVal, L"Value", &vargValue, DISPATCH\_PROPERTYGET, 0))return szValue;
              
              VARTYPE Type = vargValue.vt;
              switch(Type)
              {
              case VT\_UI1:
              	{
              		TCHAR nChr = vargValue.bVal;
              		szValue = nChr;
              	}
              	break;
              case VT\_I4:
              	{
              		long nVal = vargValue.lVal;
              		szValue.Format("%i", nVal);
              	}
              	break;
              case VT\_R4:
              	{
              		float fVal = vargValue.fltVal;
              		szValue.Format("%f", fVal);
              	}
              	break;
              case VT\_R8:
              	{
              		double dVal = vargValue.dblVal;
              		szValue.Format("%f", dVal);
              	}
              	break;
              case VT\_BSTR:
              	{
              		BSTR b = vargValue.bstrVal;
              		szValue = b;
              	}
              	break;
              case VT\_BYREF|VT\_UI1:
              	{
              		//Not tested
              		unsigned char\* pChr = vargValue.pbVal;
              		szValue = (TCHAR)\*pChr;
              	}
              	break;
              case VT\_BYREF|VT\_BSTR:
              	{
              		//Not tested
              		BSTR\* pb = vargValue.pbstrVal;
              		szValue = \*pb;
              	}
              	break;
              case 0:
              	{
              		//Empty
              		szValue = \_T("");
              	}
              	break;
              }
              

              // ReleaseVariant(&vargRng);
              // ReleaseVariant(&vargValue);

              return szValue;
              

              }

              but haven't VT_DATE and VT_DATE | VT_BYREF case ... can you give me an help hand ? I can show you what I try , but didn't working ... Thank you . P.S. I search to google , but I didn't find something appropiate ... :(

              T Offline
              T Offline
              T2102
              wrote on last edited by
              #6

              Similar to VT_R8, except that you know the range of values. It's fairly easy to convert back and forth from Excel 2003's date time serial noting the leap year error in 1900. If using Excel 2007 or 2010, you need to know what date format is being used in Excel.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups