Click here to Skip to main content
15,891,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Text Fle Filter Pin
Nishad S1-Mar-09 19:12
Nishad S1-Mar-09 19:12 
AnswerRe: Text Fle Filter Pin
Jijo.Raj1-Mar-09 21:52
Jijo.Raj1-Mar-09 21:52 
AnswerRe: Text Fle Filter Pin
Le@rner2-Mar-09 0:36
Le@rner2-Mar-09 0:36 
QuestionIs it possible to convert part of source code to library? Pin
sunny_vc1-Mar-09 15:22
sunny_vc1-Mar-09 15:22 
AnswerRe: Is it possible to convert part of source code to library? Pin
Garth J Lancaster1-Mar-09 15:55
professionalGarth J Lancaster1-Mar-09 15:55 
AnswerRe: Is it possible to convert part of source code to library? Pin
sunny_vc1-Mar-09 16:20
sunny_vc1-Mar-09 16:20 
AnswerRe: Is it possible to convert part of source code to library? Pin
Stuart Dootson1-Mar-09 21:59
professionalStuart Dootson1-Mar-09 21:59 
QuestionVC++ 6 Reading MS Excel fields Pin
RDEPTYLTD1-Mar-09 13:53
RDEPTYLTD1-Mar-09 13:53 
Visual C++ and Microsoft Excel

I am working on a project at the moment and have an issue with reading MS Excel 97 ~ 2003 spreadsheets.

My problem relates to the Excel field format of any given field in the spreadsheet, if a field is formatted in Excel to anything other than Text, then I cannot read the data from that field. for example if column A1 is formatted in excel to Text (good data returned) if A2 is formated to a number (a null is returned) if A3 is text (good data is returned), and so on.

The problem seems to be getting my code to understand the format of any particular field, Here is a snipped of my code;


1) I am using the CRecordset class to open and read the Excel spreadsheet. The spreadsheet has
defined name ranges and generally all works just fine (Provided the fields are text formatted).

2)If i use this line of code to first attempt to read what type of data is in a NUMBER field
"recset.GetODBCFieldInfo( m_csaColumnNames.GetAt(i), fieldinfo );"
I get a positive response when i try the different data types
"if(fieldinfo.m_nSQLType == SQL_VARCHAR){AfxMessageBox("SQL_VARCHAR");}"
suggesting its a data type SQL_VARCHAR data type

3) If i then call GetFieldValue to get the info from a field with a switch command

CDBVariant variant;

recset.GetFieldValue( m_csaColumnNames.GetAt(i), variant);

switch(variant.m_dwType)
{
case DBVT_SHORT:{ szValue.Format("%d", variant.m_iVal);
break;
}
case DBVT_LONG:{ szValue.Format("%d", variant.m_lVal);
break;
}
case DBVT_SINGLE:{ if ( variant.m_fltVal == 0.0 )
szValue = "Verify";
else
szValue.Format("%.1f", variant.m_fltVal);
break;
}

case DBVT_DOUBLE:{ if ( variant.m_dblVal == 0.0 )
szValue = "Verify";
else
szValue.Format("%.1f", variant.m_dblVal);
break;
}

case DBVT_DATE:{
szValue.Format("%B %d, %Y",variant.m_pdate );
break;
}

case DBVT_STRING:{ szValue = *variant.m_pstring; //szValue = V_BSTRT( &varValue );//convert BSTR to CString
break;
}

case DBVT_BOOL:{ if(variant.m_boolVal)
szValue = "TRUE";
else
szValue = "FALSE";
break;
}

case DBVT_UCHAR:{ szValue = (char*)variant.m_chVal;
break;
}

case DBVT_NULL:{
szValue = "Error Null"; AfxMessageBox(szValue);
break;
}
default:{
szValue = "\0";
break;
}
}//switch


RESULTS
All fields which are text, return a valid value which is exactly as per the Excel Spreadsheet, all fields which contains numbers or I even tried date formats in excel return DBVT_NULL which is totally useless because the cell has a number in it or a date.

SUMMARY
I have tried to read the data using GetODBCFieldInfo only and then calling the m_ member depending on the type returned which i know to be in the field, but that does not give me anything other than an unsigned short with random values that bear no resemblance to what is in the actual field.


Any help that anyone can offer in regards to solving this problem would be much appreciated and I I can get the entire class working properly I have happy to post it here for all to use.

Thanks in advance for any assistance.
AnswerRe: VC++ 6 Reading MS Excel fields Pin
Dmytro Skrypnyk23-Mar-09 11:56
Dmytro Skrypnyk23-Mar-09 11:56 
QuestionC++ reads utf-8 xml file Pin
Member 47565741-Mar-09 11:52
Member 47565741-Mar-09 11:52 
AnswerRe: C++ reads utf-8 xml file Pin
Sarath C1-Mar-09 17:36
Sarath C1-Mar-09 17:36 
QuestionGetShortPathName Pin
tom groezer1-Mar-09 9:54
tom groezer1-Mar-09 9:54 
AnswerRe: GetShortPathName Pin
Stuart Dootson1-Mar-09 10:09
professionalStuart Dootson1-Mar-09 10:09 
GeneralRe: GetShortPathName Pin
tom groezer1-Mar-09 21:08
tom groezer1-Mar-09 21:08 
GeneralRe: GetShortPathName Pin
Stuart Dootson1-Mar-09 21:55
professionalStuart Dootson1-Mar-09 21:55 
QuestionStupid Menu Question Pin
Mats Selen1-Mar-09 8:19
Mats Selen1-Mar-09 8:19 
AnswerRe: Stupid Menu Question [modified] Pin
Stuart Dootson1-Mar-09 10:06
professionalStuart Dootson1-Mar-09 10:06 
GeneralRe: Stupid Menu Question Pin
Mats Selen1-Mar-09 10:47
Mats Selen1-Mar-09 10:47 
GeneralRe: Stupid Menu Question Pin
Stuart Dootson1-Mar-09 11:29
professionalStuart Dootson1-Mar-09 11:29 
GeneralRe: Stupid Menu Question Pin
Richard Andrew x641-Mar-09 13:22
professionalRichard Andrew x641-Mar-09 13:22 
GeneralRe: Stupid Menu Question Pin
Mats Selen2-Mar-09 1:40
Mats Selen2-Mar-09 1:40 
Questiontemplate and vector [modified] Pin
transoft1-Mar-09 7:24
transoft1-Mar-09 7:24 
AnswerRe: template and vector Pin
Code-o-mat1-Mar-09 7:59
Code-o-mat1-Mar-09 7:59 
GeneralRe: template and vector Pin
transoft1-Mar-09 8:14
transoft1-Mar-09 8:14 
GeneralRe: template and vector Pin
Code-o-mat1-Mar-09 8:18
Code-o-mat1-Mar-09 8:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.