⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qexport4common.pas

📁 Advanced.Export.Component.v4.01.rar,delphi 第三方控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:

begin
  FillBackground;
  OutText;
end;
{$ENDIF}

procedure QExportCheckSource(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4
  {$IFNDEF NOGUI}; DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid{$ENDIF});
begin
  if ((ExportSource = esDataSet) and not Assigned(DataSet)) or
     ((ExportSource = esCustom) and not Assigned(CustomSource)){$IFNDEF NOGUI}or
     ((ExportSource = esDBGrid) and
      (not Assigned(DBGrid) or
       not Assigned(DBGrid.DataSource) or
       not Assigned(DBGrid.DataSource.DataSet))) or
     ((ExportSource = esListView) and not Assigned(ListView)) or
     ((ExportSource = esStringGrid) and not Assigned(StringGrid)){$ENDIF} then
    raise Exception.CreateFmt({$IFDEF WIN32}QExportLoadStr(QEM_ExportSourceNotAssigned){$ENDIF}
                              {$IFDEF LINUX}QEM_ExportSourceNotAssigned{$ENDIF},
                              [QExportSourceAsString(ExportSource)]);
end;

function QExportSource(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4
  {$IFNDEF NOGUI}; DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid{$ENDIF}): TComponent;
begin
  Result := nil;
  if ExportSource = esDataSet then
    Result := DataSet
  else if ExportSource = esCustom then
    Result := CustomSource
  {$IFNDEF NOGUI}
  else if ExportSource = esDBGrid then
    Result := DBGrid
  else if ExportSource = esListView then
    Result := ListView
  else if ExportSource = esStringGrid then
    Result := StringGrid;
  {$ENDIF}
end;

procedure QExportGetColumns(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4; 
  {$IFNDEF NOGUI}DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid;{$ENDIF} ExportedFields, AvailableCols,
  ExportedCols: TStrings);
var
  i: integer;
  WA: boolean;
  FDS: TDataSet;
begin
  QExportCheckSource(ExportSource, DataSet, CustomSource
    {$IFNDEF NOGUI}, DBGrid, ListView, StringGrid{$ENDIF});

  AvailableCols.Clear;
  ExportedCols.Clear;
  {$IFDEF NOGUI}FDS := nil;{$ENDIF}
  case ExportSource of
    esDataSet,
    esDbGrid: begin
      case ExportSource of
        esDataSet: FDS := DataSet;
        {$IFNDEF NOGUI}
        esDBGrid: FDS := DBGrid.DataSource.DataSet;
        else FDS := nil;
        {$ENDIF}
      end;
      WA := FDS.Active;
      if not FDS.Active and (FDS.FieldCount = 0) then
        try FDS.Open; except Exit; end;
      for i := 0 to FDS.FieldCount - 1 do
        if FDS.Fields[i].IsBlob
          then AvailableCols.AddObject(FDS.Fields[i].FieldName, TObject(1))
          else AvailableCols.AddObject(FDS.Fields[i].FieldName, TObject(0));
      if not WA and FDS.Active then
        try FDS.Close; except end;
    end;
    esCustom:
      for i := 0 to CustomSource.ColCount - 1 do
        AvailableCols.AddObject(CustomSource.Columns[i].ColumnName, TObject(0));
    {$IFNDEF NOGUI}
    esListView:
      for i := 0 to ListView.Columns.Count - 1 do
        AvailableCols.AddObject(ListView.Columns[i].Caption, TObject(0));
    esStringGrid:
      for i := 0 to StringGrid.ColCount - 1 do
        AvailableCols.AddObject(IntToStr(i), TObject(0));
    {$ENDIF}
  end; { case }

  for i := 0 to ExportedFields.Count - 1 do
    if AvailableCols.IndexOf(ExportedFields[i]) <> -1 then
      ExportedCols.Add(ExportedFields[i]);
  for i := AvailableCols.Count - 1 downto 0 do
    if ExportedFields.IndexOf(AvailableCols[i]) <> -1 then
      AvailableCols.Delete(i);
end;

function QExportIsActive(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4
  {$IFNDEF NOGUI}; DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid{$ENDIF}): boolean;
begin
  Result := true;
  case ExportSource of
    esDataSet: Result := DataSet.Active;
    {$IFNDEF NOGUI}
    esDBGrid: Result := DBGrid.DataSource.DataSet.Active;
    {$ENDIF}
  end;
end;

function QExportIsEmpty(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4
  {$IFNDEF NOGUI}; DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid{$ENDIF}): boolean;
begin
  Result := true;
  case ExportSource of
    esDataSet: Result := DataSet.IsEmpty;
    {$IFNDEF NOGUI}
    esDBGrid: Result := DBGrid.DataSource.DataSet.IsEmpty;
    esListView: Result := ListView.Items.Count = 0;
    esStringGrid: Result := StringGrid.RowCount = StringGrid.FixedRows;
    {$ENDIF}
  end;
end;

function QExportGetBookmark(ExportSource: TQExportSource; DataSet: TDataSet;
  CustomSource: TqeCustomSource4{$IFNDEF NOGUI}; DBGrid: TDBGrid;
  ListView: TListView; StringGrid: TStringGrid{$ENDIF}): TBookmark;
begin
  Result := nil;
  case ExportSource of
    esDataSet: Result := DataSet.GetBookmark;
    esCustom: Result := Pointer(CustomSource.RecNo);
    {$IFNDEF NOGUI}
    esDBGrid: Result := DbGrid.DataSource.DataSet.GetBookmark;
    esListView: begin
      if Assigned(ListView.Selected)
        then Result := Pointer(ListView.Selected.Index)
        else Result := Pointer(0);
    end;
    esStringGrid: Result := Pointer(StringGrid.Row);
    {$ENDIF}
  end;
end;

procedure QExportGotoBookmark(ExportSource: TQExportSource; DataSet: TDataSet;
  CustomSource: TqeCustomSource4;{$IFNDEF NOGUI}DBGrid: TDBGrid;
  ListView: TListView; StringGrid: TStringGrid;{$ENDIF} Bookmark: TBookmark);
begin
  case ExportSource of
    esDataSet: DataSet.GotoBookmark(Bookmark);
    esCustom:
      begin
        CustomSource.RecNo := Integer(Bookmark);
        CustomSource.Eof := False;
      end;
    {$IFNDEF NOGUI}
    esDBGrid: DbGrid.DataSource.DataSet.GotoBookmark(Bookmark);
    esListView: ListView.Items[Integer(Bookmark)].Selected := true;
    esStringGrid: StringGrid.Row := Integer(Bookmark);
    {$ENDIF}
  end;
end;

procedure QExportFreeBookmark(ExportSource: TQExportSource; DataSet: TDataSet;
  {$IFNDEF NOGUI}DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid;{$ENDIF} Bookmark: TBookmark);
begin
  case ExportSource of
    esDataSet: DataSet.FreeBookmark(Bookmark);
    {$IFNDEF NOGUI}
    esDBGrid: DbGrid.DataSource.DataSet.FreeBookmark(Bookmark);
    {$ENDIF}
  end;
end;

procedure QExportFirst(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4
  {$IFNDEF NOGUI};DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid{$ENDIF});
begin
  case ExportSource of
    esDataSet: DataSet.First;
    esCustom: CustomSource.First;
    {$IFNDEF NOGUI}
    esDBGrid:
      if Assigned(DBGrid) and Assigned(DBGrid.DataSource) and
         Assigned(DBGrid.DataSource.DataSet) and
         DBGrid.DataSource.DataSet.Active then
           DBGrid.DataSource.DataSet.First;
    esListView: ListView.Items[0].Selected := true;
    esStringGrid: StringGrid.Row := StringGrid.FixedRows;
    {$ENDIF}
  end;
end;

procedure QExportNext(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4;
  {$IFNDEF NOGUI}DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid;{$ENDIF} var RecordCounter: integer);
begin
  Inc(RecordCounter);
  case ExportSource of
    esDataSet: DataSet.Next;
    esCustom: CustomSource.Next;
    {$IFNDEF NOGUI}
    esDBGrid: DBGrid.DataSource.DataSet.Next;
    esStringGrid: begin
      if StringGrid.Row < StringGrid.RowCount - 1 then
        StringGrid.Row := StringGrid.Row + 1;
    end;
    {$ENDIF}
  end;
end;

procedure QExportSkip(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4;
  {$IFNDEF NOGUI}DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid;{$ENDIF} SkipRecCount: integer;
  SkipEvent: TExportedRecordEvent; Sender: TObject; var RecordCounter: integer);
var
  i: integer;
begin
  for i := 0 to SkipRecCount - 1 do begin
    QExportNext(ExportSource, DataSet, CustomSource,
     {$IFNDEF NOGUI}DBGrid, ListView, StringGrid,{$ENDIF} RecordCounter);
    if Assigned(SkipEvent) then SkipEvent(Sender, RecordCounter);
  end;
end;

function QExportEof(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4;
  {$IFNDEF NOGUI}DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid;{$ENDIF} RecordCounter, ExportRecCount,
  SkipRecCount: integer): boolean;
begin
  Result := true;
  case ExportSource of
    esDataSet: Result := DataSet.Eof;
    esCustom: Result := CustomSource.Eof or not Assigned(CustomSource.OnGetNextRecord);
    {$IFNDEF NOGUI}
    esDBGrid: Result := DBGrid.DataSource.DataSet.Eof;
    esListView:
      if ExportRecCount > 0 then
        Result := RecordCounter = MaximumInt(MinimumInt(ExportRecCount,
          ListView.Items.Count - SkipRecCount), 0)
      else
        Result := RecordCounter = MaximumInt(ListView.Items.Count -
          SkipRecCount, 0);
    esStringGrid:
      if ExportRecCount > 0 then
        Result := RecordCounter = MaximumInt(MinimumInt(ExportRecCount,
          StringGrid.RowCount - StringGrid.FixedRows - SkipRecCount), 0)
      else
        Result := RecordCounter = MaximumInt(StringGrid.RowCount -
          StringGrid.FixedRows - SkipRecCount, 0);
    {$ENDIF}
  end;
end;

procedure QExportGetColData(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource4;
  {$IFNDEF NOGUI}DBGrid: TDBGrid; ListView: TListView;
  StringGrid: TStringGrid;{$ENDIF} Columns: TQExportColumns;
  Formats: TQExportFormats; Index, RecordCounter,
  SkipRecCount: integer; var Value: QEString; var Data: Variant);
var
  DSField: TField;
  i: integer;
begin
  DSField := nil;
  case ExportSource of
    esDataSet:
      DSField := DataSet.Fields[Columns[Index].Number];
    esCustom:
      Value := CustomSource.Columns[Columns[Index].Number].AsString;
    {$IFNDEF NOGUI}
    esDBGrid:
      DSField := DBGrid.Columns[Columns[Index].Number].Field;
    esListView:
      if Columns[Index].Number = 0 then
        Value := ListView.Items[RecordCounter + SkipRecCount].Caption
      else
        Value := ListView.Items[RecordCounter + SkipRecCount].SubItems[Columns[Index].Number - 1];
    esStringGrid:
      Value := StringGrid.Cells[Columns[Index].Number, StringGrid.Row];
    {$ENDIF}
  else
    Value := EmptyStr;
  end;
  if DSField <> nil then
  begin
    VarClear(Data);
    Data := DSField.AsVariant;
    if DSField.IsNull then
      Value := Formats.NullString
    else
    if Formats.KeepOriginalFormat then
      Value := {$IFDEF QE_UNICODE}DSField.AsVariant{$ELSE}DSField.AsString{$ENDIF}
    else begin
      Formats.ApplyParams;
      try
        case DSField.DataType of
          ftSmallint, ftInteger, ftWord, ftAutoInc, ftLargeint:
            Value := FormatFloat(Columns[Index].Format, DSField.AsInteger);
          ftFloat, ftBCD:
            Value := FormatFloat(Columns[Index].Format, DSField.AsFloat);
          ftCurrency:
            if Columns[Index].Format <> EmptyStr then
              Value := FormatFloat(Columns[Index].Format, DSField.AsFloat)
            else
              Value := FloatToStrF(DSField.AsFloat, ffCurrency, 15, CurrencyDecimals);
          ftDate, ftTime, ftDateTime {$IFDEF VCL6}, ftTimeStamp{$ENDIF}:
            Value := FormatDateTime(Columns[Index].Format, DSField.AsDateTime);
          ftBoolean:
            if DSField.AsBoolean then
              Value := Formats.BooleanTrue
            else
              Value := Formats.BooleanFalse;
          ftWideString:
            Value := DSField.AsVariant;
          ftString, ftFixedChar:
            Value := DSField.AsString;
        else
          Value := DSField.AsString;
        end;
      finally
        Formats.RestoreSeparators;
      end;
    end;
  end
  else
  begin
    try
      case Columns[Index].ColType of
        ectInteger:
          begin
            Data := StrToIntDef(Value, 0);
            if not Formats.KeepOriginalFormat then
            begin
              Formats.ApplyParams;
              try
                Value := FormatFloat(Columns[Index].Format, Integer(Data));
              finally
                Formats.RestoreSeparators;
              end;
            end;
          end;
        {$IFDEF VCL6}
        ectBigint:
          begin
            Data := StrToInt64Def(Value, 0);
            if not Formats.KeepOriginalFormat then
            begin
              Formats.ApplyParams;
              try
                i := Data;
                Value := FormatFloat(Columns[Index].Format, I);
              finally
                Formats.RestoreSeparators;
              end;
            end;
          end;
        {$ENDIF}
        ectFloat:
        begin
          Data := StrToFloat(Value);
          if not Formats.KeepOriginalFormat then
          begin
            Formats.ApplyParams;
            try
              Value := FormatFloat(Columns[Index].Format, Extended(Data));
            finally
              Formats.RestoreSeparators;
            end;
          end;
        end;
        ectCurrency:
        begin
          Data := StrToFloat(Value);
          if not Formats.KeepOriginalFormat then
          begin
            Formats.ApplyParams;
            try
              Value := FormatFloat(Columns[Index].Format, Extended(Data

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -