unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs, Excel2010,
Vcl.StdCtrls,
Vcl.OleServer;
type
TForm1 =
class(TForm)
ExcelApplication1: TExcelApplication;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ExcelWorkbook1: TExcelWorkbook;
ExcelWorksheet1: TExcelWorksheet;
ExcelOLEObject1: TExcelOLEObject;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
flcid: Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
flcid:=GetUserDefaultLCID;
ExcelApplication1.Connect;
ExcelApplication1.Visible[flcid]:=true;
ExcelApplication1.UserControl:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ExcelApplication1.Quit;
ExcelApplication1.Disconnect;
end;
procedure TForm1.Button3Click(Sender: TObject);
var svalue, filename:
String;
begin
filename := ExtractFilePath(ParamStr(0))+'
Mappe1.xls';
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Open(filename,
emptyParam,emptyParam,emptyParam,emptyParam,emptyParam,emptyParam,
emptyParam,emptyParam,emptyParam, emptyParam, emptyParam,
emptyParam, emptyParam, emptyParam, flcid));
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item[1]
as ExcelWorkSheet);
sValue:=ExcelWorksheet1.Range['
B1','
B1'].Value;
messagedlg(sValue,mtInformation,[mbOK],0);
end;
end.