Экспорт из cxGrid в Excel

zaroman
Дата: 06.06.2011 15:45:39
Помогите, пожалуйста!
Нужно было сделать в cxGrid-е summary не просто Count, а distinct count. Нашел у Dev-а на сайте:

 
procedure TForm1.viewCountryCustomDrawFooterCell(Sender: TcxGridTableView;
  ACanvas: TcxCanvas; AViewInfo: TcxGridColumnHeaderViewInfo;
  var ADone: Boolean);
var
  I, DataGroupIndex: Integer;
  GridRecord: TcxCustomGridRow;
  Column: TcxGridDBColumn;
  vi: TcxGridRowFooterCellViewInfo;
 
  RecordIndexes: TList;
  DisctinctList: TStringList;
begin
  if AViewInfo is TcxGridRowFooterCellViewInfo then   // Row footer
  begin
    vi := AViewInfo as TcxGridRowFooterCellViewInfo;
    Column := TcxGridDBTableSummaryItem(vi.SummaryItem).Column as TcxGridDBColumn;
 
    if Column.DataBinding.FieldName = 'Area' then  // Area column
    begin
      GridRecord := vi.GridRecord;
      DataGroupIndex := Sender.DataController.Groups.DataGroupIndexByRowIndex[GridRecord.Index];
      if DataGroupIndex <> -1 then
      begin
        RecordIndexes := TList.Create;
        DisctinctList := TStringList.Create;
        DisctinctList.Sorted := True;
        DisctinctList.Duplicates := dupIgnore;
 
        try
          Sender.DataController.Groups.LoadRecordIndexes(RecordIndexes, DataGroupIndex);
 
          for I := 0 to RecordIndexes.Count - 1 do
            DisctinctList.Add(Sender.DataController.Values[Integer(RecordIndexes[I]), Column.Index]);
 
          AViewInfo.Text := 'Disctinct count: ' + IntToStr(DisctinctList.Count);
        finally
          RecordIndexes.Free;
          DisctinctList.Free;
        end;
      end;
    end;
  end;
end;

Вроде работает, но есть одно "но". При экспорте в Excel все итоги пересчитываются! Подскажите, можно ли это как-то побороть?
zaroman
Дата: 07.06.2011 16:25:16
Нашел возможность устанавливать значения вручную

 <View>.DataController.Summary.FooterSummaryValues[0] := 10;
Только теперь непонятно, в какое событие это вставлять? И как пробегаться по всем группам в таблице?