Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create an excel spreadsheet?

Hello,
Im interested how to create the *.xls file with NI Library. I cant find the right function. Usually, Im using following code (ODBC):
 
CDatabase database;
  CString sDriver = "MICROSOFT EXCEL DRIVER (*.XLS)"; // exactly the same name as in the ODBC-Manager
  CString sExcelFile = "c:\\demo.xls";                // Filename and path for the file to be created
  CString sSql;

  TRY
  {
    // Build the creation string for access without DSN

    sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s", sDriver,sExcelFile,sExcelFile);

    // Create the database (i.e. Excel sheet)
    if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
    {
      // Create table structure
      sSql = "CREATE TABLE demo (Name TEXT,Age NUMBER)";
      database.ExecuteSQL(sSql);

      // Insert data
      sSql = "INSERT INTO demo (Name,Age) VALUES ('Bruno Brutalinsky',45)";
      database.ExecuteSQL(sSql);

      sSql = "INSERT INTO demo (Name,Age) VALUES ('Fritz Pappenheimer',30)";
      database.ExecuteSQL(sSql);

      sSql = "INSERT INTO demo (Name,Age) VALUES ('Hella Wahnsinn',28)";
      database.ExecuteSQL(sSql);
    }

    // Close database
    database.Close();
  }
  CATCH_ALL(e)
  {
    TRACE1("Driver not installed: %s",sDriver);
  }
  END_CATCH_ALL;

 

I looked for the function with parameters like sExcelFile but i cant find the right. Do You have any idea How to work with NI Library and Excel files. If it will be possible, send me a procedure or example.... Thank you very much for help and advice.

emta


0 Kudos
Message 1 of 3
(4,276 Views)
There are two examples that ship with Measurement Studio that demonstrate how to use the Measurement Studio C++ classes to interface to Excel. The examples are installed to the following locations by default:
 
C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\Office\ExcelAdvanced
C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\Office\ExcelReport
 
The top level class that you use in this API is CNiExcelApplication. You should be able to find this through the Index in the Measurement Studio help.
 
One point to note that this API controls the Excel application through its ActiveX automation interface. This is different than the approach you are using above and so will require that you write different code to accomplish your task.
0 Kudos
Message 2 of 3
(4,274 Views)
Thank You very much. emta
0 Kudos
Message 3 of 3
(4,221 Views)