anchor.diff:      procedure SaveSettings (aStream : TStream);
       procedure EnableSort (aSortManager : ISortableDatasetManager);
       procedure EnableHeaderPopupMenu (aOriginalGridPopupMenu : TPopupMenu);
  -    procedure ExportGridAsCsv (aStream : TStream);
  +    procedure ExportGridAsCsv (aStream : TStream); overload;
  +    procedure ExportGridAsCsv (Sender : TObject); overload;
  +    procedure ExportGridAsXls (aStream : TStream); overload;
  +    procedure ExportGridAsXls (Sender : TObject); overload;
   
       property Grid : TDBGrid read FDBGrid;
     end;
  
positive.code:   FSortManager := nil;
    FDBGrid := nil;
    FSettings.Free;
    inherited Destroy;
  end;
  
  
negative.code:     end;
      FDBGrid.DataSource.DataSet.RecNo:= rn;
  
  
    finally
      FDBGrid.DataSource.DataSet.EnableControls;
    end;
  end;
  
  procedure TmDBGridHelper.ExportGridAsCsv(Sender : TObject);
  begin
    ExportGridToFile('CSV');
  end;
  
  {$IFDEF FPC}
  
  procedure TmDBGridHelper.ExportGridAsXls(aStream: TStream);
  var
    MyWorkbook: TsWorkbook;
    MyWorksheet : TsWorksheet;
    tmpFields : TFields;
    i, rn, row : integer;
  begin
    MyWorkbook := TsWorkbook.Create;
    try
      MyWorksheet := MyWorkbook.AddWorksheet('Sheet1');
  
      FDBGrid.DataSource.DataSet.DisableControls;
      try
        tmpFields := FDBGrid.DataSource.DataSet.Fields;
        for i := 0 to tmpFields.Count - 1 do
        begin
          MyWorksheet.WriteText(0, i, tmpFields[i].DisplayLabel);
          MyWorksheet.WriteBackgroundColor(0, i, $00D0D0D0);
        end;
  
        rn := FDBGrid.DataSource.DataSet.RecNo;
        row := 1;
  
        FDBGrid.DataSource.DataSet.First;
        while not FDBGrid.DataSource.DataSet.EOF do
        begin
          for i := 0 to tmpFields.Count - 1 do
          begin
            if not tmpFields[i].IsNull then
            begin
              if (tmpFields[i].DataType = ftSmallint) or (tmpFields[i].DataType = ftInteger) or (tmpFields[i].DataType = ftLargeint) then
                MyWorksheet.WriteNumber(row, i, tmpFields[i].AsFloat, nfGeneral, 0)
              else
              if (tmpFields[i].DataType = ftFloat) then
                MyWorksheet.WriteNumber(row, i, tmpFields[i].AsFloat)
              else
              if (tmpFields[i].DataType = ftDate) or (tmpFields[i].DataType = ftDateTime) or (tmpFields[i].DataType = ftTime) or (tmpFields[i].DataType = ftTimeStamp) then
                MyWorksheet.WriteDateTime(row, i, tmpFields[i].AsDateTime)
              else
              if (tmpFields[i].DataType = ftBoolean) then
                MyWorksheet.WriteBoolValue(row, i, tmpFields[i].AsBoolean)
              else
                MyWorksheet.WriteText(row, i, tmpFields[i].AsString);
            end;
          end;
  
          inc(row);
          FDBGrid.DataSource.DataSet.Next;
        end;
        FDBGrid.DataSource.DataSet.RecNo:= rn;
  
      finally
        FDBGrid.DataSource.DataSet.EnableControls;
      end;
      MyWorkbook.WriteToStream(aStream, sfExcel8);
    finally
      MyWorkbook.Free;
    end;
  end;
  
  procedure TmDBGridHelper.ExportGridAsXls(Sender : TObject);
  begin
    ExportGridToFile('XLS');
  end;
  
  {$ELSE}
  
  procedure TmDBGridHelper.ExportGridAsXls(aStream: TStream);
  begin
    // TODO
  end;
  {$ENDIF}
  
  end.
  