anchor.diff:    end;
   end;
   
  +function TmDBGridHelper.ConfirmFileOverwrite: boolean;
  +begin
  +  Result := MessageDlg('Confirm', 'The selected file already exists. Overwrite it?', mtConfirmation, mbYesNo, 0) = mrYes;
  +end;
  +
  +procedure TmDBGridHelper.ExportGridToFile(aFileType: String);
  +var
  +  fs : TFileStream;
  +  oldCursor : TCursor;
  +begin
  +  if aFileType = 'CSV' then
  +  begin
  +    FSaveDialog.DefaultExt:= 'csv';
  +    FSaveDialog.Filter:='Comma Separated Values files|*.csv';
  +  end
  +  else
  +  if aFileType = 'XLS' then
  +  begin
  +    FSaveDialog.DefaultExt:= 'xls';
  +    FSaveDialog.Filter:='Excel 97-2003 files|*.xls';
  +  end;
  +  if FSaveDialog.Execute then
  +  begin
  +    if FileExists(FSaveDialog.FileName) then
  +    begin
  +      if not ConfirmFileOverwrite then
  +        exit;
  +    end;
  +    try
  +      oldCursor := Screen.Cursor;
  +      try
  +        Screen.Cursor:= crHourGlass;
  +        fs := TFileStream.Create(FSaveDialog.FileName, fmCreate);
  +        try
  +          if aFileType = 'CSV' then
  +            Self.ExportGridAsCsv(fs)
  +          else if aFileType = 'XLS' then
  +            Self.ExportGridAsXls(fs);
  +        finally
  +          fs.Free;
  +        end;
  +      finally
  +        Screen.Cursor:= oldCursor;
  +      end;
  +    except
  +      on E:Exception do
  +      begin
  +        MessageDlg('Unable to write file. Check if the file is open by another application. If so, close it and run this command again.', mtInformation, [mbOk], 0);
  +      end;
  +    end;
  +  end;
  +
  +end;
  +
   constructor TmDBGridHelper.Create(aGrid : TDBGrid);
   begin
     FSettings := TmGridColumnsSettings.Create;
     FSortManager := nil;
     FDBGrid := aGrid;
  +  FSaveDialog := TSaveDialog.Create(nil);
   end;
   
   destructor TmDBGridHelper.Destroy;
  
positive.code:     procedure SaveSettings (aStream : TStream);
      procedure EnableSort (aSortManager : ISortableDatasetManager);
      procedure EnableHeaderPopupMenu (aOriginalGridPopupMenu : TPopupMenu);
      procedure ExportGridAsCsv (aStream : TStream);
  
      property Grid : TDBGrid read FDBGrid;
    end;
  
negative.code:     FHeaderPopupMenu : TPopupMenu;
      FCurrentGridCol : longint;
      FGridPopupMenu : TPopupMenu;
      FSaveDialog: TSaveDialog;
      // original events
      FOriginalOnTitleClick : TDBGridClickEvent;
      FOriginalOnMouseDown : TMouseEvent;
      procedure OnTitleClick (Column: TColumn);
      procedure OnMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      procedure BuildHeaderPopupMenu;
      function ConfirmFileOverwrite : boolean;
      procedure ExportGridToFile(aFileType : String);
    public
      constructor Create(aGrid : TDBGrid);
      destructor Destroy; override;
  