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

📄 qexport3common.pas

📁 DELPHI开发VCL
💻 PAS
📖 第 1 页 / 共 4 页
字号:
            if X1 = Y1 then begin
              MoveTo(X1, Y1);
              LineTo(X2, Y2);
              MoveTo(X1, Y1 + 2);
              LineTo(X2, Y2 + 2);
            end
            else begin
              MoveTo(X1, Y1 - 2);
              LineTo(X2, Y2 - 2);
              MoveTo(X1, Y1);
              LineTo(X2, Y2);
            end;
          end;
          if Y1 <> Y2 then begin
            if X1 = Y1 then begin
              MoveTo(X1, Y1);
              LineTo(X2, Y2);
              MoveTo(X1 + 2, Y1);
              LineTo(X2 + 2, Y2);
            end
            else begin
              MoveTo(X1 - 2, Y1);
              LineTo(X2 - 2, Y2);
              MoveTo(X1, Y1);
              LineTo(X2, Y2);
            end;
          end;
        end;

      end;

    end;
  end;

  procedure DrawBorders;
  begin
    if Format.Borders.Top.Style <> bstNone then
      DrawBorderLine(2, 2, PaintBox.Width - 2, 2, Format.Borders.Top);
    if Format.Borders.Bottom.Style <> bstNone then
      DrawBorderLine(2, PaintBox.Height - 2, PaintBox.Width - 2,
        PaintBox.Height - 2, Format.Borders.Bottom);
    if Format.Borders.Left.Style <> bstNone then
      DrawBorderLine(2, 2, 2, PaintBox.Height - 2, Format.Borders.Left);
    if Format.Borders.Right.Style <> bstNone then
      DrawBorderLine(PaintBox.Width - 2, 2, PaintBox.Width - 2,
        PaintBox.Height - 2, Format.Borders.Right);
  end;

  procedure DrawPatterns;
  var
    X, Y: integer;
  begin
    X := 0;
    Y := 0;
    {$IFDEF LINUX}
    PaintBox.Canvas.Brush.Style := bsSolid;
    {$ENDIF}
    PaintBox.Canvas.Brush.Color := ColorByXLSColor(Format.Fill.Background);
    PaintBox.Canvas.FillRect(Rect(0, 0, PaintBox.Width, PaintBox.Height));
    PaintBox.Canvas.Pen.Width := 1;
    PaintBox.Canvas.Pen.Color := ColorByXLSColor(Format.Fill.Foreground);
    while Y <= PaintBox.Height - 4 do begin
      while X <= PaintBox.Width do begin
        DrawPattern(PaintBox.Canvas, Integer(Format.Fill.Pattern), X, Y);
        Inc(X, 4);
      end;
      Inc(Y, 4);
      X := 0;
    end
  end;

begin
  DrawPatterns;
  OutText;
  DrawBorders;
end;

procedure DrawRTFSample(PaintBox: TPaintBox; rtfStyle: TrtfStyle);
  procedure FillBackground;
  begin
    if rtfStyle.AllowBackground
      then  PaintBox.Canvas.Brush.Color := rtfStyle.BackgroundColor
      else  PaintBox.Canvas.Brush.Color := clWhite;
    PaintBox.Canvas.FillRect(Rect(0, 0, PaintBox.Width, PaintBox.Height));
  end;

  procedure OutText;
  const
    TXT = 'Aa Zz';
  var
    H, W, X, Y: integer;
  begin
    with PaintBox.Canvas.Font do begin
      Name := rtfStyle.Font.Name;
      Size := rtfStyle.Font.Size;
      Charset := rtfStyle.Font.Charset;
      Color := rtfStyle.Font.Color;
      Style := rtfStyle.Font.Style;
    end;

    H := PaintBox.Canvas.TextHeight(TXT);
    W := PaintBox.Canvas.TextWidth(TXT);
    if H > PaintBox.Height then
      H := PaintBox.Height;
    if W > PaintBox.Width then
      W := PaintBox.Width;
//    X := 5;
    X := (PaintBox.Width - W) div 2;
    Y := (PaintBox.Height - H) div 2;

    if rtfStyle.AllowHighlight and
         (rtfStyle.HighlightColor <> rtfStyle.BackgroundColor) then begin
      PaintBox.Canvas.Brush.Color := rtfStyle.HighlightColor;
      PaintBox.Canvas.FillRect(Rect(X, Y, X + W, Y + H));
    end;

{    case Format.Alignment.Horizontal of
      halGeneral,
      halLeft,
      halFill: X := 5;
      halCenter: X := (PaintBox.Width - PaintBox.Canvas.TextWidth(TXT)) div 2;
      halRight: X := PaintBox.Width - 5 - PaintBox.Canvas.TextWidth(TXT);
      else X := 0;
    end;

    case Format.Alignment.Vertical of
      valTop: Y := 5;
      valCenter: Y := (PaintBox.Height - PaintBox.Canvas.TextHeight(TXT)) div 2;
      valBottom: Y := PaintBox.Height - 5 - PaintBox.Canvas.TextHeight(TXT);
      else Y := 0;
    end;}

    PaintBox.Canvas.TextOut(X, Y, TXT);

    //otm.otmSize := SizeOf(otm);
    //GetOutlineTextMetrics(PaintBox.Canvas.Handle, otm.otmSize, @otm);
  end;

begin
  FillBackground;
  OutText;
end;
{$ENDIF}

procedure QExportCheckSource(ExportSource: TQExportSource;
  DataSet: TDataSet; CustomSource: TqeCustomSource
  {$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: TqeCustomSource
  {$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: TqeCustomSource; 
  {$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: TqeCustomSource
  {$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: TqeCustomSource
  {$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: TqeCustomSource{$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: TqeCustomSource;{$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: TqeCustomSource
  {$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: TqeCustomSource;
  {$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: TqeCustomSource;
  {$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: TqeCustomSource;
  {$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;

function QExportFormatData(const DataStr, Format: string;
  ColType: TQExportColType; NormalFunc: TNormalFunc): string;
begin
  try
    Result := DataStr;
    case ColType of
      ectInteger:
        Result := NormalFunc(FormatFloat(Format, StrToIntDef(Result, 0)));
      {$IFNDEF VCL3}
      ectBigint:
        Result := NormalFunc(FormatFloat(Format, StrToInt64Def(Result, 0)));
      {$ENDIF}
      ectFloat:
        Result := NormalFunc(FormatFloat(Format, StrToFloat(Result)));
      ectCurrency:
        Result := NormalFunc(FormatFloat(Format, StrToFloat(Result)));
      ectDate:
        Result := NormalFunc(FormatDateTime(Format, StrToDateTime(Result)));
      ectTime:
        Result := NormalFunc(FormatDateTime(Format, StrToDateTime(Result)));
      ectDateTime:
        Result := NormalFunc(FormatDateTime(Format, StrToDateTime(Result)));
      ectString: Result := NormalFunc(Result);
      else Result := NormalFunc(Result); //igorp 镳

⌨️ 快捷键说明

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