How to Read Excel File in VC++....

Hi Guys,
              If you want to read your Excel sheet using  c++ application then don't worry go for the below mentioned steps and connect your apps and with c++.But before doing this you need to install the Visual Studio 6.0 and develop a win32 console application with c++ source file.

STEPS:


      1. Keep libxl-3.1.0 inside c headerfiles.
      2. Include include folder of libxl into vc++ Tools->options->Directories include files.





3. Include the library file of libxl in vc++6.0 Tools->options->Directories library files.




  4. Include the bin file of libxl in vc++6.0 Tools->options->Directories Executable files.


     

5.      Keep the libxl.dll in current working folder.




                     Sample Code for reading Excel file  in C++:

#include <iostream>
      #include <wchar.h>
      #include "libxl.h"
      #pragma comment(lib, "libxl")
      using namespace std;
      using namespace libxl;

      //extract data from an existing spreadsheet
      void main()
     {

            Book* book = xlCreateBook();
           
           if(book)
          {
                        if(book->load("data.xls"))
                        {
                                    Sheet* sheet = book->getSheet(0);
                                    if(sheet)
                                    {
                                                string s, s1, s2, s3,s4;
                                                double d,d1,d2,d3,d4,d5;

                                                // Read 1st row of the spreadsheet
                                                d = sheet->readNum(0, 0);
                                                cout << d << endl;

                                                s= sheet->readStr(0, 1);
                                                cout << s.c_str() << endl;

                                                d1 = sheet->readNum(0, 2);
                                                cout << d1 << endl;

                                                d2 = sheet->readNum(0, 3);
                                                cout << d2 << endl;
                                                                       
                                                // Read 2nd row of the spreadsheet
                                                d3 = sheet->readNum(1, 0);
                                                cout << d3 << endl;

                                                s1= sheet->readStr(1, 1);
                                                cout << s1.c_str() << endl;

                                                d4 = sheet->readNum(1, 2);
                                                cout << d4 << endl;

                                                d5 = sheet->readNum(1, 3);
                                                cout << d5 << endl;                                       


                                    }
                        }

                        book->release();
            }

}

    Gud  luck.....


Comments

Popular posts from this blog

Window could not start the Apache tomcat 6 on Local Computer.For more information, review the System Events Logs.If this is a non-Microsoft service,contact service vendor, and refer to service-specific error code 0.

ORACLE DBA INTERVIEW QUESTION & ANSWERS