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. Reading from Excel

Reading from Excel

Scheduled Pinned Locked Moved C / C++ / MFC
3 Posts 3 Posters 2 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.
  • A Offline
    A Offline
    Anu_Bala
    wrote on last edited by
    #1

    I want to read from Excel file. Pls provide me with any class or sample project that i can use with my application.

    H Z 2 Replies Last reply
    0
    • A Anu_Bala

      I want to read from Excel file. Pls provide me with any class or sample project that i can use with my application.

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See Reading Excel files using ODBC[^]_**


      **_

      whitesky


      1 Reply Last reply
      0
      • A Anu_Bala

        I want to read from Excel file. Pls provide me with any class or sample project that i can use with my application.

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

        you can find the CRecordset in the web... it can open the excel as database void CExDlg::OnRead() { // TODO: Add your control notification handler code here CDatabase database; CString sDriver; CString sDsn; CString sFile,sPath; //find the excel in main exe folder GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind ('\\'); sPath=sPath.Left (nPos); sFile = sPath + "\\Demo.xls"; //name of excel sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s", sDriver, sFile); TRY { database.Open(NULL, false, false, sDsn); CRecordset recset(&database); CString sSql; sSql = "SELECT item FROM Regt WHERE item = 'iwant' "; // // exe SQL recset.Open(CRecordset::forwardOnly, sSql, CRecordset::readOnly); BYTE line = 1; // »ñÈ¡²éѯ½á¹û while (!recset.IsEOF()) { //¶ÁÈ¡ExcelÄÚ²¿ÊýÖµ recset.GetFieldValue("item", sitem); // read out the item line++; //ÏÔʾ¼ÇÈ¡µÄÄÚÈÝ m_listbox.AddString( sitem); // ÒÆµ½ÏÂÒ»ÐÐ recset.MoveNext(); } // close database.Close(); } CATCH(CDBException, e) { // Êý¾Ý¿â²Ù×÷²úÉúÒ쳣ʱ... AfxMessageBox("error: " + e->m_strError); } END_CATCH; }

        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