procedure ExportStrGrid(fileType : TfileType;stringgrid : TStringGrid;SaveFileName : string);
var
ExcelApp: Variant;
Arow,Acol : Word;
stringlist : TStringlist;
lines : string;
begin
case fileType of
Excel : begin
try
ExcelApp := Createoleobject('Excel.Application');
ExcelApp.workbooks.add;
except
raise Exception.Create('你没有安装Excel!');
end;
for Arow := 0 to stringgrid.RowCount-1 do
for Acol := 0 to stringgrid.ColCount-1 do
ExcelApp.worksheets['sheet1'].cells[arow+1,Acol+1].value := stringgrid.Cells[Acol,arow];
ExcelApp.activeworkbook.saveas(savefilename);
ExcelApp.activeworkbook.close;
end;
txt : begin
stringlist := TStringlist.Create;
for Arow := 0 to stringgrid.RowCount-1 do
begin
lines := '';
for Acol := 0 to stringgrid.ColCount-1 do
lines := lines+stringgrid.Cells[Acol,arow]+' , ';
stringlist.Add(lines);
end;
stringlist.SaveToFile(SaveFileName);
stringlist.Free;
end;
end;
end;