问题1:LoginPrompt := False;
问题2:
使用OLE自动化对象建立同EXCEL的连接,并在DELPHI下面编程控制EXCEL。
首先,应该在USES中加入一个ComObj。这是非常重要的。然后创建一个EXCEL类型的COM对象,实现如下:
V := CreatOleObject( 'Excel Application ');
V.Visible := true;
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleServer, Excel2000(也可以是Excel97);
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
XLApp: Variant;
procedure InsertData;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses ComObj;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if not VarIsEmpty(XLApp) then begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
XLApp := CreateOleObject('Excel.Application');
XLApp.Visible := True;
XLApp.Workbooks.Add(xlWBatWorkSheet); //
XLApp.Workbooks[1].WorkSheets[1].Name := 'Delphi Data';
InsertData;
end;
procedure TForm1.InsertData;
var
i: integer;
Sheet: Variant;
begin
Sheet := XLApp.Workbooks[1].WorkSheets['Delphi Data'];
for i := 1 to 10 do
begin
Sheet.Cells[i,1] := i;
//用上面这种形式,把你的数据插进去就行了。
end;
Sheet.Cells[i,1] := '=Sum(A1: A10)'
end;
end.