home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 October / Chip_2002-10_cd1.bin / zkuste / delphi / kolekce / d56 / FLEXCEL.ZIP / Demo / UReport.pas < prev    next >
Pascal/Delphi Source File  |  2002-07-01  |  3KB  |  144 lines

  1. unit UReport;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   OleCtnrs, ExtCtrls, ToolWin, ComCtrls, OleCtrls, SHDocVw_TLB, UFlDemoData,
  8.   ActnList, Activex, UWaitCursor,
  9.   {$IFDEF ConditionalExpressions}{$if CompilerVersion >= 14} variants,{$IFEND}{$ENDIF} //Delphi 6 or above
  10.   {$IFDEF Excel97}Excel97, {$ELSE} Excel2000, {$ENDIF}
  11.  
  12.   Menus, SHDocVw;
  13.  
  14. type
  15.   TReport = class(TForm)
  16.     Panel1: TPanel;
  17.     ToolBar: TToolBar;
  18.     ToolButton5: TToolButton;
  19.     ToolBar1: TToolBar;
  20.     ToolButton1: TToolButton;
  21.     ActionList1: TActionList;
  22.     ActionPrint: TAction;
  23.     ActionPrintPreview: TAction;
  24.     ActionZoom: TAction;
  25.     ActionClose: TAction;
  26.     ToolButton3: TToolButton;
  27.     ToolButton4: TToolButton;
  28.     ToolButton6: TToolButton;
  29.     ToolButton7: TToolButton;
  30.     WB: TWebBrowser;
  31.     PopZoom: TPopupMenu;
  32.     N501: TMenuItem;
  33.     N1001: TMenuItem;
  34.     N2001: TMenuItem;
  35.     N751: TMenuItem;
  36.     ToolButton2: TToolButton;
  37.     procedure ActionCloseExecute(Sender: TObject);
  38.     procedure ActionPrintPreviewExecute(Sender: TObject);
  39.     procedure ActionPrintExecute(Sender: TObject);
  40.     procedure N501Click(Sender: TObject);
  41.     procedure N1001Click(Sender: TObject);
  42.     procedure N2001Click(Sender: TObject);
  43.     procedure ActionZoomExecute(Sender: TObject);
  44.     procedure N751Click(Sender: TObject);
  45.     procedure FormShow(Sender: TObject);
  46.   private
  47.     procedure SetZoom(const Zoom: integer);
  48.     { Private declarations }
  49.   public
  50.     { Public declarations }
  51.   end;
  52.  
  53. implementation
  54.  
  55. {$R *.DFM}
  56.  
  57. procedure TReport.ActionCloseExecute(Sender: TObject);
  58. begin
  59.   Close;
  60. end;
  61.  
  62. procedure TReport.ActionPrintPreviewExecute(Sender: TObject);
  63. var
  64.   pvain, pvaout:Olevariant;
  65.   v: IOleCommandTarget;
  66.   WaitCursor: IWaitCursor;
  67. begin
  68.   WaitCursor:=TWaitCursor.Create;
  69.   //Couldnt find a way to implement this for excel files...
  70.    pvain:=null; pvaout:=null;
  71.    v:=WB.Document as IOleCommandTarget;
  72.    try
  73.      if v<>nil then v.exec(nil, OLECMDID_PRINTPREVIEW, 0,pvain,pvaout);
  74.    finally
  75.      v._Release;   //This is not automatically unreleased... dont ask why.
  76.    end; //finally
  77. end;
  78.  
  79. procedure TReport.ActionPrintExecute(Sender: TObject);
  80. var
  81.   pvain, pvaout:Olevariant;
  82.   v: IOleCommandTarget;
  83.   WaitCursor: IWaitCursor;
  84. begin
  85.   WaitCursor:=TWaitCursor.Create;
  86.    pvain:=null; pvaout:=null;
  87.    v:=WB.Document as IOleCommandTarget;
  88.    try
  89.      if v<>nil then v.exec(nil, OLECMDID_PRINT, 0,pvain,pvaout);
  90.    finally
  91.      v._Release;
  92.    end; //finally
  93. end;
  94.  
  95. procedure TReport.SetZoom(const Zoom: integer);
  96. var
  97.   v: _Workbook;
  98. begin
  99.   if not Supports(WB.Document, _Workbook, v) then exit;
  100.    try
  101.      if v<>nil then v.Windows[1].Zoom:=Zoom;
  102.    finally
  103.      v._Release;
  104.    end; //finally
  105. end;
  106.  
  107. procedure TReport.N501Click(Sender: TObject);
  108. begin
  109.   SetZoom(50);
  110. end;
  111.  
  112. procedure TReport.N1001Click(Sender: TObject);
  113. begin
  114.   SetZoom(100)
  115. end;
  116.  
  117. procedure TReport.N2001Click(Sender: TObject);
  118. begin
  119.   SetZoom(200);
  120. end;
  121.  
  122. procedure TReport.ActionZoomExecute(Sender: TObject);
  123. begin
  124.   //Nothing
  125. end;
  126.  
  127. procedure TReport.N751Click(Sender: TObject);
  128. begin
  129.   SetZoom(75);
  130. end;
  131.  
  132.  
  133. procedure TReport.FormShow(Sender: TObject);
  134. var
  135.   v: _workbook;
  136. begin
  137.   ActionZoom.Enabled:=Supports(WB.Document, _Workbook, v);
  138.   if v<>nil then v._Release;
  139.   ActionZoom.Visible:=ActionZoom.Enabled;
  140. end;
  141.  
  142. end.
  143.  
  144.