MS‘s BUG? why can't get value from excel?
-
i want to get value from excel,for example: COLUMN1 COLUMN2 ---------------- 123 456 ABC DEF 123 ABC EFG HIJ like this,i can't get '123' ,but i can get 'ABC'. my code : void ReadTrustListFromExcel(CString sFile) { CDatabase database; CString sSql; CString sItem1, sItem2; CString sDriver; CString sDsn; sDriver = GetExcelDriver();//GetExcelDriver(); if (sDriver.IsEmpty()) { return; } sDsn.Format(_T("ODBC;DRIVER={%s};DSN='';DBQ=%s"), sDriver, sFile); TRY { database.Open(NULL, false, false, sDsn); CRecordset recset(&database); sSql.Format(_T("SELECT * FROM [%s$A1:IV65535]"),_T("EmailSheet")); recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly); while (!recset.IsEOF()) { recset.GetFieldValue(short(0), sItem1); recset.GetFieldValue(short(1), sItem2); TRACE(_T("name:%s,addr:%s\r\n"),sItem1,sItem2); recset.MoveNext(); } database.Close(); } CATCH(CDBException, e) { TRACE(_T("ERROR")); } END_CATCH;
-
i want to get value from excel,for example: COLUMN1 COLUMN2 ---------------- 123 456 ABC DEF 123 ABC EFG HIJ like this,i can't get '123' ,but i can get 'ABC'. my code : void ReadTrustListFromExcel(CString sFile) { CDatabase database; CString sSql; CString sItem1, sItem2; CString sDriver; CString sDsn; sDriver = GetExcelDriver();//GetExcelDriver(); if (sDriver.IsEmpty()) { return; } sDsn.Format(_T("ODBC;DRIVER={%s};DSN='';DBQ=%s"), sDriver, sFile); TRY { database.Open(NULL, false, false, sDsn); CRecordset recset(&database); sSql.Format(_T("SELECT * FROM [%s$A1:IV65535]"),_T("EmailSheet")); recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly); while (!recset.IsEOF()) { recset.GetFieldValue(short(0), sItem1); recset.GetFieldValue(short(1), sItem2); TRACE(_T("name:%s,addr:%s\r\n"),sItem1,sItem2); recset.MoveNext(); } database.Close(); } CATCH(CDBException, e) { TRACE(_T("ERROR")); } END_CATCH;
ZhiLiangLin wrote:
sDsn.Format(_T("ODBC;DRIVER={%s};DSN='';DBQ=%s"), sDriver, sFile);
Is the value of
sDsn
correct?ZhiLiangLin wrote:
sSql.Format(_T("SELECT * FROM [%s$A1:IV65535]"),_T("EmailSheet"));
Have you tried:
sSql.Format(_T("SELECT * FROM [%s$A1:B4]"), _T("EmailSheet"));
Does it have anything to do with those cells containing numbers? Do any of the rows read correctly?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
ZhiLiangLin wrote:
sDsn.Format(_T("ODBC;DRIVER={%s};DSN='';DBQ=%s"), sDriver, sFile);
Is the value of
sDsn
correct?ZhiLiangLin wrote:
sSql.Format(_T("SELECT * FROM [%s$A1:IV65535]"),_T("EmailSheet"));
Have you tried:
sSql.Format(_T("SELECT * FROM [%s$A1:B4]"), _T("EmailSheet"));
Does it have anything to do with those cells containing numbers? Do any of the rows read correctly?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
the api 'getfieldvalue' can't get the value.
-
the api 'getfieldvalue' can't get the value.
So have you used the debugger to step into that method to find out why?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch