Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Delphi controls MS Office applications
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
How can you remote control MS Office applications from your Delphi application? The Answer is to use a TOLEContainer.
It requires some interface knowledge to use the right object(s) and their properties. Some samples are added to Delphi demos, but all of them are targeted at MSWord. I have posted examples for Internet Explorer elsewhere and here is a sample for MSExcel:  | |  | |
procedure TForm1.OleContainer1Activate(Sender: TObject);
var
ExcelSheet: Variant;
Count,
Curent: Variant;
i,
j: Integer;
begin
Count := OleContainer1.OleObject.Application.Sheets.Count;
Curent := StrToInt(OKBottomDlg.Edit2.Text);
if Curent<>0 then
begin
if Curent<=Count then
begin
OleContainer1.OleObject.Application.Sheets[Count].Activate;
ExcelSheet := OleContainer1.OleObject.Application.ActiveSheet;
ExcelSheet.name := OKBottomDlg.Edit3.Text+IntToStr(Count);
for i := 0 to StringGrid1.RowCount do
begin
for j := 0 to StringGrid1.ColCount do
begin
ExcelSheet.Cells(i, j) := StringGrid1.Cells[j, i]
end
end;
end
else begin
for i := Count+1 to Curent do
begin
OleContainer1.OleObject.Application.Sheets.Add
end;
OleContainer1.OleObject.Application.Sheets[Curent].Activate;
ExcelSheet := OleContainer1.OleObject.Application.ActiveSheet;
ExcelSheet.name := OKBottomDlg.Edit3.Text+IntToStr(Count);
for i := 0 to StringGrid1.RowCount do
begin
for j := 0 to StringGrid1.ColCount do
begin
ExcelSheet.Cells(i, j) := StringGrid1.Cells[j, i]
end
end;
end
end;
end; | |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|
anonymous from China
|
 |
|
|
|
|