Retrieving data from excel sheet

How can i retrieve the data from an excel sheet to my MFC Program.
Who is Participating?
V245Connect With a Mentor Commented:
You can use ODBC. At first you should make ODBC data source. Than you can use CRecordset and CRecordView classes. If it is a new application the AppWizard can help you (turn on Database view with or without file support).

Use Excel as an out-of-process OLE object to open the spreadsheet then examine the data within it.
dloadsAuthor Commented:
But if i use the CDatabase::Open command like this-->
      CDatabase *pDB = new CDatabase;
      pDB->Open("D:\\test\\test.xls" , FALSE , FALSE , "ODBC;Excel 5.0;");
It's opening up the DSN dialog box and asking for the DSN.  But i want it completely automated and the i may have to open different spreadsheets each time this program is called.

I'm not quite sure I understand your explanation correct. So there are two variants below:

1. If you need to work with a specific worksheet you should register an appropriate Data Source and make something like this:


If DSN is correct an additional dialog will not appear.

2. If you want to choose different worksheets use this way (sure, ODBC Excel driver must be installed):

          pDB->OpenEx("DSN=Excel Files;");

In this case dialog "Select Worksheet" appears and you can choose necessary one .
All Courses

From novice to tech pro — start learning today.