DELPHI中控制EXCEL的一个例子
来源:互联网 发布:软件检测员 编辑:程序博客网 时间:2024/06/10 20:12
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
ExcelApp: Variant;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
Path: string;
begin
Path := ExtractFilePath(Application.exeName);
if copy(Path, length(Path) ,1) <> '/' then
Path := Path + '/';
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.WorkBooks.Open(Path+'Book2.xlt');
Button1.Enabled := False;
Button2.Enabled := True;
Button3.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Path: string;
begin
try
Path := ExtractFilePath(Application.exeName);
if copy(Path, length(Path) ,1) <> '/' then
Path := Path + '/';
ExcelApp.WOrkBooks[1].SaveAs(Path+'test.xls');
finally
Button1.Enabled := True;
Button2.Enabled := False;
Button3.Enabled := False;
ExcelApp.WOrkBooks.Close;
ExcelApp.Quit;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
Book: Variant;
Sheet: Variant;
AfterSheet: Variant;
begin
Book := ExcelApp.WorkBooks[1];
AfterSheet := Book.WorkSheets[3];
Sheet := Book.WorkSheets.Add(EmptyParam, AfterSheet, 1);
//Sheet.move(Book.WorkSheets[4],
//Sheet := Book.WorkSheets[1];
Sheet.Activate;
ExcelApp.Cells[3,1] := 'TEST';
end;
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
ExcelApp: Variant;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
Path: string;
begin
Path := ExtractFilePath(Application.exeName);
if copy(Path, length(Path) ,1) <> '/' then
Path := Path + '/';
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.WorkBooks.Open(Path+'Book2.xlt');
Button1.Enabled := False;
Button2.Enabled := True;
Button3.Enabled := True;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Path: string;
begin
try
Path := ExtractFilePath(Application.exeName);
if copy(Path, length(Path) ,1) <> '/' then
Path := Path + '/';
ExcelApp.WOrkBooks[1].SaveAs(Path+'test.xls');
finally
Button1.Enabled := True;
Button2.Enabled := False;
Button3.Enabled := False;
ExcelApp.WOrkBooks.Close;
ExcelApp.Quit;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
Book: Variant;
Sheet: Variant;
AfterSheet: Variant;
begin
Book := ExcelApp.WorkBooks[1];
AfterSheet := Book.WorkSheets[3];
Sheet := Book.WorkSheets.Add(EmptyParam, AfterSheet, 1);
//Sheet.move(Book.WorkSheets[4],
//Sheet := Book.WorkSheets[1];
Sheet.Activate;
ExcelApp.Cells[3,1] := 'TEST';
end;
end.
- DELPHI中控制EXCEL的一个例子
- DELPHI中控制EXCEL的一个例子
- Delphi 控制Excel 例子,参考资料
- Delphi中控制Excel
- Delphi中控制Excel
- Delphi中启动控制面板中的程序的例子
- Delphi控制Excel的整理
- Delphi控制Excel的方法
- 一个Socket5的例子(Delphi)
- Delphi EnumWindows 的一个例子
- Delphi控制PowerPoint完整的例子
- Delphi控制Excel的方法 OLE
- Delphi控制Excel的方法 OLE
- Delphi控制Excel的经验(二) 分享
- Delphi控制Excel的经验(一)
- Delphi 控制Excel
- Delphi控制Excel
- Delphi自动化控制Excel
- 将Flex与Spring框架集成
- c# list 转IList
- Busybox v1.1.3 (debian1:1.1.3-5 ubuntu12)问题的解决
- javaScript代码收集
- 计算机类期刊投稿心得
- DELPHI中控制EXCEL的一个例子
- 加入数据图表,完善论文
- 木马的防范
- 浅谈ASP.NET的权限管理和用户验证
- VARIANT类型的用法
- 专业IT顾问写的教程 一步一步 截图 安装OCS 很详细
- 减少线程占用cpu
- 流媒体的概念
- 在ASP.NET中显示事件日志记录