poniedziałek, 19 września 2022

Connecting to Word and Excel (C++ Builder)


 

private: // User declarations


        Variant m_Excel;

        Variant m_Word;


TForm1 *Form1;


PropertySet to_Word("Visible");

PropertySet to_Excel("Visible");

Procedure close_Word("Quit");

Procedure close_Excel("Quit");


//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

        : TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

 try

 {

  m_Excel=Variant::CreateObject("Excel.Application");

  to_Excel<<true;

  m_Excel.Exec(to_Excel);

 }

 catch(...)

 {

  ShowMessage("i can't open. Excel is not installed!");

 }

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

 try

 {

  m_Word=Variant::CreateObject("Word.Application");

  to_Word<<true;

  m_Word.Exec(to_Word);

 }

 catch(...)

 {

  ShowMessage("I can't open. Word is not installed!");

 }

}


//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{

 try

 {

  close_Excel<<false;

  m_Excel.Exec(close_Excel);

  m_Excel=Unassigned;

 }

 catch(...)

 {

  ShowMessage("Excel is not installed!");

 }

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

 try

 {

  close_Word<<false;

  m_Word.Exec(close_Word);

  m_Word=Unassigned;


 }

 catch(...)

 {

  ShowMessage("Word is not installed!");

 }

}

Brak komentarzy:

Prześlij komentarz