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. MS‘s BUG? why can't get value from excel?

MS‘s BUG? why can't get value from excel?

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasedebuggingtutorialquestion
4 Posts 2 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.
  • Z Offline
    Z Offline
    ZhiLiangLin
    wrote on last edited by
    #1

    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;

    D 1 Reply Last reply
    0
    • Z ZhiLiangLin

      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;

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      Z 1 Reply Last reply
      0
      • D David Crow

        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

        Z Offline
        Z Offline
        ZhiLiangLin
        wrote on last edited by
        #3

        the api 'getfieldvalue' can't get the value.

        D 1 Reply Last reply
        0
        • Z ZhiLiangLin

          the api 'getfieldvalue' can't get the value.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          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