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

📄 urealexcel.pas

📁 韩国的一个数据表控件2 很好用 支持D4-5 一共5个 Korea, a data table control
💻 PAS
字号:
unit URealExcel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  URGrids, URMGrid, UCustomExcel;

type
  { TRealExcel }
  TRealExcel = class(TwCustomExcel)
  private
    FGridColAttrib: Boolean;
    (* property methods *)
    function  GetGrid: TRealGrid;
    procedure SetGrid(V: TRealGrid);
    procedure SetGridColAttrib(const Value: Boolean);

  protected
    function ConvertBody(rStart: Integer): Integer; override;

  public
    constructor Create(AComponent: TComponent); override;
    destructor  Destroy; override;
    PROCEDURE Print;
    PROCEDURE PrintPreView;
    (* properties *)

  published
    (* properties from TwCustomExcel *)
    property AutoFit;
    property Title;
    property Header;
    property Footer;
    property FileName;
//    property RowNumber;
    property SheetName;
    property ShowExcel;
    property BorderColor; 
    property BorderStyle;
    property BorderWeight;

    property GridColAttrib : Boolean read FGridColAttrib write SetGridColAttrib;
    (* properties *)
    property Grid: TRealGrid read GetGrid write SetGrid;
  end;

implementation

uses UExcelUtils, UEXcelPrograss;

{ TRealExcel }
//== init & final ====================================================================//
constructor TRealExcel.Create(AComponent: TComponent);
begin
  inherited;
end;

destructor TRealExcel.Destroy;
begin
  inherited;
end;

//== property methods ================================================================//
function TRealExcel.GetGrid: TRealGrid;
begin
  Result := TRealGrid(inherited Grid);
end;

procedure TRealExcel.SetGrid(V: TRealGrid);
begin
  inherited Grid := V;
end;

//== override methods ================================================================//
function TRealExcel.ConvertBody(rStart: Integer): Integer;

  function DrawColumn(ARow: Integer): Integer;
  var
    S : String;
    bNum: Integer;
    G,
    i,J,K,L   : Integer;
    r   : OleVariant;
    Arr : OleVariant;
    MCol : TwMemColumn;
    vCol : TwColumn;
  begin
    bNum := Ord(RowNumber);

    with Grid do
    begin

      Arr := VarArrayCreate([0,RowCount, 0,ColCount+2], varVariant );

      If groupMode Then
        for i := 0 to Grid.RowCount - 1 do
        Begin
          Arr[i,0] := I+1;
          L := 1;
          for J := 0 to VGroupCount - 1 do
            for k := 0 to Vgroups[ j ].ColCount[0] - 1 do
            begin
              If TwMemColumn( ColumnByVCell( wCell( J, 0, K ) )).DataType = wdtString Then
                Arr[i,L] := ''''+Cells[ ColumnByVCell( wCell( J, 0, K ) ).Index, I ].Text
              Else
                Arr[i,L] := cells[ ColumnByVCell( wCell( J, 0, K ) ).Index, I ].Text;
              Inc(L);
            End;
          Excel_process( I );
        End
      Else
        for i := 0 to Grid.RowCount - 1 do
        Begin
          Arr[i,0] := I+1;
          L := 1;
          for J := 0 to VColCount - 1 do
          begin
              If TwMemColumn( VColumns[j] ).DataType = wdtString Then
                Arr[i,J+1] := ''''+Cells[ VColumns[j].Index , i].Text
              Else
                Arr[i,J+1] := Cells[ VColumns[j].Index , i].Text;
            Inc(L);
          End;
          Excel_process( I );
        End;

      r := GetRange(1, rStart, L+1 {VColCount}, RStart+RowCount-1);
      R.value := Arr;

      r := GetRange(1, rStart, 1 , RStart+RowCount-1);

      with Indicators do
      begin
        SetBorder(r);
        r.HorizontalAlignment := _EXCEL_HALIGN[Alignment];
        r.VerticalAlignment   := _EXCEL_VALIGN[Layout];
        _Convert(Font, r.Font);
        r.Interior.Color      := ColorToRGB(Color);
      end;

      // 拿烦阑 盔贰狼 拿烦栏肺 函版茄促.
      Result := 1;
      // 拿烦阑 器窃 救且波搁...
      If not FGridColAttrib Then Exit;

      If groupMode Then
      begin
        L := 2;
        for J := 0 to VGroupCount - 1 do
        Begin
            for k := 0 to Vgroups[ j ].ColCount[0] - 1 do
            begin
              vCol := ColumnByVCell( wCell( J,0,k ) );
              r := GetRange(L, rStart, L, RStart+RowCount-1);
              SetBorder(r);
              r.HorizontalAlignment := _EXCEL_HALIGN[vCol.Alignment];
              r.VerticalAlignment   := _EXCEL_VALIGN[vCol.Layout];
              _Convert(vCol.Font, r.Font);
              r.Interior.Color      := ColorToRGB(vCol.Color);

              Inc(L);
            End;
          Excel_process( I + J );
        End;
      End
      Else
      Begin
        for J := 0 to VColCount - 1 do
        begin
          vCol := vColumns[j];
          r := GetRange(j+2, rStart, J+2, RStart+RowCount-1);
          SetBorder(r);
          r.HorizontalAlignment := _EXCEL_HALIGN[vCol.Alignment];
          r.VerticalAlignment   := _EXCEL_VALIGN[vCol.Layout];
          _Convert(vCol.Font, r.Font);
          r.Interior.Color      := ColorToRGB(vCol.Color);
          Excel_process( I + J );
        End;
      End;

    End;
    Result := 1;
  end;

  function DrawGroup(APos, ARow: Integer): Integer;
  var
    g      : TwExcelGroups;
    x      : Integer;
    i, j, k: Integer;
    r, c   : OleVariant;
  begin
    g  := FGroups;
    x  := 1;

    with Grid do
    begin
      if RowNumber then
      begin
        r := GetRange(x, APos, x, APos + g.RowHeight - 1);
        r.Merge;

        with Indicators do
        begin
          SetBorder(r);
          r.HorizontalAlignment := _EXCEL_HALIGN[Alignment];
          r.VerticalAlignment   := _EXCEL_VALIGN[Layout];
          _Convert(Font, r.Font);
          r.Interior.Color      := ColorToRGB(Color);
          r.Value               := ARow + 1;
        end;

        Inc(x);
      end;

      for i := 0 to VGroupCount - 1 do
      begin
        r := GetRange(x, APos, x + g[i].Width - 1, APos + g.RowHeight - 1);

        with VGroups[i] do
          for j := 0 to Levels - 1 do
            for k := 0 to ColCount[j] - 1 do
            begin
                with g[i][j, k] do
//                  c := GetRange(r, X1, Y1, X2, Y2);
                  c := GetRange(X+ X1-1, aPos+ Y1-1,X+ X2-1, aPos+ Y2-1);
                c.Merge;

                If not FGridColAttrib Then
                begin
                  with Columns[j, k] do
                    If TwMemColumn( ColumnByCell( wCell( I, J, K ) )).DataType = wdtString Then
                       c.Value := ''''+Cells[ColumnByCell(WCell(i, j, k)).Index, ARow].Text
                    Else
                      c.Value := Cells[ColumnByCell(WCell(i, j, k)).Index, ARow].Text;
                End
                Else
                begin
                  with Columns[j, k] do
                  begin
                    SetBorder(c);
                    c.HorizontalAlignment := _EXCEL_HALIGN[Alignment];
                    c.VerticalAlignment   := _EXCEL_VALIGN[Layout];
                    _Convert(Font, c.Font);
                    c.Interior.Color      := ColorToRGB(Color);
                  end;
                End;
            end;

        Inc(x, g[i].Width);
      end;
    end;

    Result := g.RowHeight;
  end;

var
  i: Integer;
  p: Integer;
  r: OleVariant;
begin
  Result := 0;
  if Grid.RowCount < 1 then Exit;

  I := 0;
  If not grid.ColumnMode Then
    for i := 0 to Grid.ColCount - 1 do
      If grid.Columns[i].Level > 0 Then
        Break;

  If ( i = grid.ColCount ) or Grid.ColumnMode then
  begin
    if not AutoFit then
    begin
    
      r := GetRange(1, rStart, 1, rStart + Grid.RowCount - 1);

      if Grid.Indicators.Visible then
        r.ColumnWidth := (Grid.Indicators.Width + 7) div 8
      else
        r.ColumnWidth := Length(IntToStr(Grid.RowCount)) + 1;
    end;
//    for i := 0 to Grid.RowCount - 1 do
//      Inc(Result, DrawColumn(i));

      Excel_Set( grid.RowCount + grid.ColCount );
      DrawColumn(0);

    Result := ReSult + grid.RowCount;
    rStart := rStart + grid.RowCount;
  end
  else
  begin
    FGroups.Load(Self);

    if not AutoFit then
    begin
      r := GetRange(1, rStart, 1, rStart + FGroups.RowHeight - 1);

      if Grid.Indicators.Visible then
        r.ColumnWidth := (Grid.Indicators.Width + 7) div 8
      else
        r.ColumnWidth := Length(IntToStr(Grid.RowCount)) + 1;
    end;

    p := rStart;

    // 饭骇捞 0焊促 农搁 绢驴荐 绝捞 槐槐捞 捣促. 决梅 蠢扼促. 窍唱究 笼绢 持绢具 窍扁锭巩俊...
      Excel_Set( grid.RowCount );
      for i := 0 to Grid.RowCount - 1 do
      Begin
        Inc(Result, DrawGroup(p + Result, i));
        Excel_process(i+1);
      End;

  end;
end;


procedure TRealExcel.SetGridColAttrib(const Value: Boolean);
begin
  FGridColAttrib := Value;
end;

procedure TRealExcel.PrintPreView;
begin
  // 橇赴飘 茄促..
  ShowExcel := True;
  COnvert;
  FSheet.printpreview;
  FBook.Close(false);
  FExcel.Quit;

end;

procedure TRealExcel.Print;
begin
  // 橇赴飘 茄促..
  ShowExcel := False;
  COnvert;
  FSheet.print;
  FBook.Close(false);
  FExcel.Quit;

end;

end.

⌨️ 快捷键说明

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