Unit1.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:3k
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, OleCtrls, OALib_TLB;
- type
- TForm1 = class(TForm)
- Office1: TOffice;
- btnCreateWord: TButton;
- btnCreateExcel: TButton;
- btnCreatePPT: TButton;
- btnOpenOffice: TButton;
- btnShowToolbars: TButton;
- btnPrint: TButton;
- btnOpenServer: TButton;
- btnSaveServer: TButton;
- btnClose: TButton;
- btnExit: TButton;
- procedure btnCreateWordClick(Sender: TObject);
- procedure btnCreateExcelClick(Sender: TObject);
- procedure btnCreatePPTClick(Sender: TObject);
- procedure btnOpenOfficeClick(Sender: TObject);
- procedure btnShowToolbarsClick(Sender: TObject);
- procedure btnPrintClick(Sender: TObject);
- procedure btnOpenServerClick(Sender: TObject);
- procedure btnSaveServerClick(Sender: TObject);
- procedure btnCloseClick(Sender: TObject);
- procedure btnExitClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.btnCreateWordClick(Sender: TObject);
- begin
- Office1.CreateNew('Word.Document')
- end;
- procedure TForm1.btnCreateExcelClick(Sender: TObject);
- begin
- Office1.CreateNew('Excel.Sheet')
- end;
- procedure TForm1.btnCreatePPTClick(Sender: TObject);
- begin
- Office1.CreateNew('PowerPoint.Slide')
- end;
- procedure TForm1.btnOpenOfficeClick(Sender: TObject);
- begin
- Office1.OpenLocalDialog()
- end;
- procedure TForm1.btnShowToolbarsClick(Sender: TObject);
- begin
- if(Office1.GetToolbarsIsShow) then
- Office1.ShowToolbars(false)
- else
- Office1.ShowToolbars(true);
- end;
- procedure TForm1.btnPrintClick(Sender: TObject);
- begin
- Office1.Print();
- end;
- procedure TForm1.btnOpenServerClick(Sender: TObject);
- begin
- Office1.OpenWebFile('http://www.officeocx.com/demo/Sample.doc')
- end;
- procedure TForm1.btnSaveServerClick(Sender: TObject);
- begin
- if(Office1.IsOpen()) then
- Office1.SaveWebFile('http://www.officeocx.com/demo/SaveFile.php');
- //You can find your save file in http://www.officeocx.com/demo/temp.doc.
- //The SaveFile.php get the post request and save it to temp.doc.
- //Or you can call OA1.SaveWebFile('http://localhost/demo/UploadAction.aspx?FileName=temp.doc');
- //Or you can write a receipt method to get the Http stream.
- end;
- procedure TForm1.btnCloseClick(Sender: TObject);
- begin
- Office1.Close();
- end;
- procedure TForm1.btnExitClick(Sender: TObject);
- begin
- Application.Terminate;
- end;
- end.