Reading from Excel
-
I want to read from Excel file. Pls provide me with any class or sample project that i can use with my application.
-
I want to read from Excel file. Pls provide me with any class or sample project that i can use with my application.
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; }