Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi everybody,

I'm trying to open a Excel File using VC++ 2005 but i get a compiling error.

I proceed like this:

Firstly, I add the references "Microsoft Excel 9.0 Object Library" and "Microsoft Office 9.0 Object Library"

Secondly, I add the excel namespace

C++
using namespace System;
using namespace System::IO;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace Excel;


Then I declare the following variables

C++
public:
    
    Excel::ApplicationClass^ xExcel;
    Excel::Workbooks^ xWorkbooks;
    Excel::Worksheets^ xWorksheets;


and finally I try to create an instance of the Excel application as follows:

C++
private: System::Void openToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) 
{
  OpenFileDialog^ OFDB = gcnew OpenFileDialog;
  Stream^ InputFile;
  OFDB->InitialDirectory = "c:\\";
  OFDB->Filter = "xls files (*.xls)|*.xls";
  OFDB->FilterIndex = 2;
  OFDB->RestoreDirectory = true;
  if ( OFDB->ShowDialog() == System::Windows::Forms::DialogResult::OK )
  { 
      xExcel=gcnew Excel::ApplicationClass();
    //xExcel->Visible=true;     
  }
}


But I get the following compiling error in the code line "xExcel=gcnew Excel::ApplicationClass();"

d:\visual studio projects\vc++\excel file handler\excel file handler\Form1.h(150) : error C3699: '^' : cannot use this indirection on type 'Office::Assistant'

compiler replacing '^' with '*' to continue parsing

This diagnostic occurred while importing type 'Excel::_Application ' from assembly 'Interop.Excel.1.3, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null'.

This diagnostic occurred while importing type 'Excel::ApplicationClass ' from assembly 'Interop.Excel.1.3, Version=1.3.0.0, Culture=neutral, PublicKeyToken=null'.

d:\visual studio projects\vc++\excel file handler\excel file handler\Form1.h(150) : error C3699: '^' : cannot use this indirection on type 'Office::Assistant'
.
.
.


Could anybody help me with this please?

Thanks
Posted
Updated 12-Feb-10 3:44am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900