При нажатии на кнопку открывается файл таблицы Excel. Скрытый режим открытия и выход из Excel.

 

 

Unit1.cpp

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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <Comobj.hpp> //Хидер для OLE объктов
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 Variant Ap, Bs; //Переменные   EA - Application, B-Workbooks
 Ap = CreateOleObject("Excel.Application");
 Bs = Ap.Exec(PropertyGet("Workbooks"));
 Bs.Exec(Function("Open") << L"c:\\excel\\data.xlsx");   //Наш файл Excel
 Ap.Exec(PropertySet("Visible") << true); //Видимость   Excel
 //Ap.Exec(Procedure("Quit"));  //Выход из Excel
}
//---------------------------------------------------------------------------

Unit1.h

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

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TButton *Button1;
	void __fastcall Button1Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif