procedure TransToExcel;
var
MsExcel: Variant;
begin
try
MsExcel:=CreateOleObject('Excel.Application');
except
ShowMessage('无法打开Microsoft Excel');
exit;
end;
MsExcel.Visible:=True;
MsExcel.WorkBooks.Add;
if FDataFrom is TStringGrid then
TransStringGridToExcel(FDataFrom As TStringGrid,MsExcel);
if FDataFrom is TDecisionGrid then
TransDecisionGridToExcel(FDataFrom As TDecisionGrid,MsExcel);
if FDataFrom is TDBGrid then
TransDBGridToExcel(FDataFrom As TDBGrid,MsExcel);
end;
procedure TransDecisionGridToExcel(DG1:TDecisionGrid;MsExcel:Variant);
var
i,j:Integer;//循环变量
begin
ColNum:=0;
RowNum:=0;
with DG1do
begin
ColNum:=ColCount;
RowNum:=RowCount;
For j:=-2 to RowNum-3do
For i:=-1 to ColNum-2do
MsExcel.Cells[j+3,i+2].Value:=Cells[i,j];
end;
{end with}
end;
{end Prodedure}
{===========================================================================}