How can I treat VT_DATE ?
-
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 ... :(
-
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 ... :(
Initialize (i.e. construct) a
COleDateTime
object withvargValue.date
and then useCOleDateTime
'sFormat
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] -
Initialize (i.e. construct) a
COleDateTime
object withvargValue.date
and then useCOleDateTime
'sFormat
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] -
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] -
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] -
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 ... :(
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.