如何使用Delphi中Server组件。例如:如何用ExcelApplication来往WorkSheet中添加数据库字段的内容!(150分)

  • 主题发起人 PowerCMM
  • 开始时间
P

PowerCMM

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用Delphi中Server组件。例如:如何用ExcelApplication来往WorkSheet中添加
数据库字段的内容!请提供一定的源代码!谢谢了!答案正确,立马送上150分!
 
to windxy:
谢谢你的程序,但我现在还想增加一点能在Excel中看到我填的表的记录值!麻烦你在
指明一下,谢谢!
 
windwy:麻烦你用源码表示一下好吗!我试了一下,不能成功!先谢了!
 
用OLE调入你保存的文件。
放个TOleContainer控件
 
用OLE调入你保存的文件。
放个TOleContainer控件

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, Db, DBTables, Excel97, OleServer;

type
TForm1 = class(TForm)
DataSource1: TDataSource;
Table1: TTable;
DBGrid1: TDBGrid;
Button1: TButton;
SaveDialog1: TSaveDialog;
ExcelApplication1: TExcelApplication;
ExcelWorkbook1: TExcelWorkbook;
ExcelWorksheet1: TExcelWorksheet;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var row, i: integer;
begin
if SaveDialog1.Execute then
begin
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet);
row := 2;
table1.First;
while not table1.Eof do
begin
for i := 0 to table1.Fields.Count - 1 do
begin
ExcelWOrkSheet1.Cells.Item[row, i + 1] := table1.Fields.AsString;
end;
row := row + 1;
table1.Next;
end;

ExcelWorkBook1.SaveCopyAs(SaveDialog1.FileName);
ExcelWOrkBook1.Close(false);
panel2.Visible := false;
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
Screen.Cursor := crDefault;
Application.MessageBox('保存完毕!', '消息', 0);
OleContainer1.CreateObjectFromFile(SaveDialog1.FileName,false);//新加的代码
end;
end;

end.

 
在原来的程序中改过了,你看一下
 
多人接受答案了。
 
顶部