怎么在Word里画表格? 怎么在Word里画表格? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://community.csdn.net/Expert/topic/3370/3370314.xml?temp=.9221002代码里有简单的画表格 那你就在菜单里找‘表格-插入-表格’就行了,你到底在想什么?难道用DELPHI在WORD里画表吗? chinaliujacky(失落之城) 可爱了。 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, Db, DBTables, OleServer, Word97, clipbrd, Word2000, WordXP, ADODB;type TMyFirstThread = class(TThread) private protected procedure Execute;override; end;type TForm1 = class(TForm) ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DBGrid1: TDBGrid; DataSource1: TDataSource; Button1: TButton; Button2: TButton; WordDocument: TWordDocument; WordApplication: TWordApplication; WordFont: TWordFont; ChkBoxNewDoc: TCheckBox; ADOQuery2: TADOQuery; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private procedure SetFontSize(); public Thread1:TMyFirstThread; end;var Form1: TForm1;implementationuses Variants;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin ADOQuery1.Close; ADOQuery1.SQL.Text:='SELECT * FROM PT_WSMS WHERE (WSLX=''0'' OR WSLX=''1'' OR WSLX=''5'' OR WSLX=''6'') AND (Ltrim(Rtrim(HelpTitle))='''' OR HelpTitle IS NULL)'; ADOQuery1.Open;end;procedure TForm1.Button2Click(Sender: TObject);begin Thread1:=TMyFirstThread.Create(False); Thread1.Priority:=tpNormal; Thread1.FreeOnTerminate:=True;end;procedure TForm1.SetFontSize;begin WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font); WordFont.Name:='宋体'; WordFont.Size:=9;end;{ TMyFirstThread }procedure TMyFirstThread.Execute;var Docs, Template, NewTemplate, ItemIndex: OleVariant; i,j:integer; RecCount:integer;begin with Form1 do begin try Template := EmptyParam; NewTemplate := True; ItemIndex := 1; try Wordapplication.Connect; except MessageDlg('Word没有安装!', mtError, [mbOk], 0); Abort; end; Wordapplication.Visible := True; WordApplication.Caption := '文书详细'; Template := EmptyParam; {创建新的文档} NewTemplate := False; Docs := WordApplication.Documents; Docs.Add(NewTemplate := True); WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex)); {WordDocument组件赋值} WordApplication.Options.CheckSpellingAsYouType := False; {关闭拼写检查,如果进行拼写检查,将减缓Winword速度} WordApplication.Options.CheckGrammarAsYouType := False; WordDocument.Sentences.Last.Paste; WordDocument.Range.Text := ''; {插入数据} i:=1; while not ADOQuery1.Eof do begin j:=6; ADOQuery2.Close; ADOQuery2.SQL.Text:='select sysobjects.name as tablename,syscolumns.name as columnname,sysproperties.value as discription from '; ADOQuery2.SQL.Add('sysobjects,syscolumns,sysproperties where '); ADOQuery2.SQL.Add('sysobjects.name='''+Trim(ADOQuery1.FieldByName('TableName').AsString)+''' and syscolumns.id = sysobjects.id and sysproperties.smallid= syscolumns.colid and sysproperties.id = sysobjects.id'); ADOQuery2.Open; RecCount:=ADOQuery2.RecordCount+5; WordDocument.Tables.Add(WordDocument.Words.Last,RecCount,4,EmptyParam,EmptyParam); WordDocument.Range.InsertAfter('' + #13); WordDocument.Tables.Item(i).Cell(1,1).Merge(WordDocument.Tables.Item(i).Cell(1,2)); WordDocument.Tables.Item(i).Cell(1,2).Merge(WordDocument.Tables.Item(i).Cell(1,3)); WordDocument.Tables.Item(i).Cell(2,1).Merge(WordDocument.Tables.Item(i).Cell(2,2)); WordDocument.Tables.Item(i).Cell(2,2).Merge(WordDocument.Tables.Item(i).Cell(2,3)); WordDocument.Tables.Item(i).Cell(3,1).Merge(WordDocument.Tables.Item(i).Cell(3,2)); WordDocument.Tables.Item(i).Cell(3,2).Merge(WordDocument.Tables.Item(i).Cell(3,3)); WordDocument.Tables.Item(i).Cell(4,1).Merge(WordDocument.Tables.Item(i).Cell(4,4)); WordDocument.Tables.Item(i).Cell(1,1).Range.Text := '文书名称'; SetFontSize; WordDocument.Tables.Item(i).Cell(1,2).Range.Text := ADOQuery1.FieldByName('WritName').AsString; SetFontSize; WordDocument.Tables.Item(i).Cell(2,1).Range.Text := '对应表名'; SetFontSize; WordDocument.Tables.Item(i).Cell(2,2).Range.Text := ADOQuery2.FieldByName('TableName').AsString; SetFontSize; WordDocument.Tables.Item(i).Cell(3,1).Range.Text := 'ID号'; SetFontSize; WordDocument.Tables.Item(i).Cell(3,2).Range.Text := ADOQuery1.FieldByName('ID').AsString; SetFontSize; WordDocument.Tables.Item(i).Cell(5,1).Range.Text := '字段名'; SetFontSize; WordDocument.Tables.Item(i).Cell(5,2).Range.Text := '中文名称'; SetFontSize; WordDocument.Tables.Item(i).Cell(5,3).Range.Text := '是否系统生成'; SetFontSize; WordDocument.Tables.Item(i).Cell(5,4).Range.Text := '是否必填字段'; SetFontSize; while not ADOQuery2.Eof do begin WordDocument.Tables.Item(i).Cell(j,1).Range.Text:=ADOQuery2.FieldByName('columnname').AsString; SetFontSize; WordDocument.Tables.Item(i).Cell(j,2).Range.Text:=ADOQuery2.FieldByName('discription').AsString; SetFontSize; j:=j+1; ADOQuery2.Next; end; ADOQuery1.Next; i:=i+1; end; except on E: Exception do begin ShowMessage(E.Message); WordApplication.Disconnect; end; end; end;end;end. 怎样获取内存? delphi 监视网页变化问题????????????? delphi中double型转化成int型的问题 大家用什么列表控件,用于代替listview的? 怎样卸载外壳扩展的DLL? 怎麼知道控件焦點发生改变?注意,並不是一個一般的問題,請進: 我用Tquery查询数据结果显示在DBGrid中,怎么不能修改呢? 有关时间格式的问题,请帮忙 怎么让鼠标移到某个button上就在状态拦上显示相应的注解? 20分换一个Delphi 6的序列号! 关于IntraWeb的一些基础问题。 Access中更新语句为什么不能使用分组?
代码里有简单的画表格
可爱了。
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, Db, DBTables, OleServer,
Word97, clipbrd, Word2000, WordXP, ADODB;
type
TMyFirstThread = class(TThread)
private protected
procedure Execute;override;
end;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Button1: TButton;
Button2: TButton;
WordDocument: TWordDocument;
WordApplication: TWordApplication;
WordFont: TWordFont;
ChkBoxNewDoc: TCheckBox;
ADOQuery2: TADOQuery;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
procedure SetFontSize();
public
Thread1:TMyFirstThread;
end;var
Form1: TForm1;implementationuses Variants;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
ADOQuery1.Close;
ADOQuery1.SQL.Text:='SELECT * FROM PT_WSMS WHERE (WSLX=''0'' OR WSLX=''1'' OR WSLX=''5'' OR WSLX=''6'') AND (Ltrim(Rtrim(HelpTitle))='''' OR HelpTitle IS NULL)';
ADOQuery1.Open;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
Thread1:=TMyFirstThread.Create(False);
Thread1.Priority:=tpNormal;
Thread1.FreeOnTerminate:=True;
end;procedure TForm1.SetFontSize;
begin
WordFont.ConnectTo(WordDocument.Sentences.Get_Last.Font);
WordFont.Name:='宋体';
WordFont.Size:=9;
end;{ TMyFirstThread }procedure TMyFirstThread.Execute;
var
Docs, Template, NewTemplate, ItemIndex: OleVariant;
i,j:integer;
RecCount:integer;
begin
with Form1 do
begin
try
Template := EmptyParam;
NewTemplate := True;
ItemIndex := 1;
try
Wordapplication.Connect;
except
MessageDlg('Word没有安装!', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := '文书详细';
Template := EmptyParam; {创建新的文档}
NewTemplate := False;
Docs := WordApplication.Documents;
Docs.Add(NewTemplate := True);
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex)); {WordDocument组件赋值}
WordApplication.Options.CheckSpellingAsYouType := False; {关闭拼写检查,如果进行拼写检查,将减缓Winword速度}
WordApplication.Options.CheckGrammarAsYouType := False;
WordDocument.Sentences.Last.Paste;
WordDocument.Range.Text := ''; {插入数据}
i:=1;
while not ADOQuery1.Eof do
begin
j:=6;
ADOQuery2.Close;
ADOQuery2.SQL.Text:='select sysobjects.name as tablename,syscolumns.name as columnname,sysproperties.value as discription from ';
ADOQuery2.SQL.Add('sysobjects,syscolumns,sysproperties where ');
ADOQuery2.SQL.Add('sysobjects.name='''+Trim(ADOQuery1.FieldByName('TableName').AsString)+''' and syscolumns.id = sysobjects.id and sysproperties.smallid= syscolumns.colid and sysproperties.id = sysobjects.id');
ADOQuery2.Open;
RecCount:=ADOQuery2.RecordCount+5;
WordDocument.Tables.Add(WordDocument.Words.Last,RecCount,4,EmptyParam,EmptyParam);
WordDocument.Range.InsertAfter('' + #13);
WordDocument.Tables.Item(i).Cell(1,1).Merge(WordDocument.Tables.Item(i).Cell(1,2));
WordDocument.Tables.Item(i).Cell(1,2).Merge(WordDocument.Tables.Item(i).Cell(1,3));
WordDocument.Tables.Item(i).Cell(2,1).Merge(WordDocument.Tables.Item(i).Cell(2,2));
WordDocument.Tables.Item(i).Cell(2,2).Merge(WordDocument.Tables.Item(i).Cell(2,3));
WordDocument.Tables.Item(i).Cell(3,1).Merge(WordDocument.Tables.Item(i).Cell(3,2));
WordDocument.Tables.Item(i).Cell(3,2).Merge(WordDocument.Tables.Item(i).Cell(3,3));
WordDocument.Tables.Item(i).Cell(4,1).Merge(WordDocument.Tables.Item(i).Cell(4,4));
WordDocument.Tables.Item(i).Cell(1,1).Range.Text := '文书名称';
SetFontSize;
WordDocument.Tables.Item(i).Cell(1,2).Range.Text := ADOQuery1.FieldByName('WritName').AsString;
SetFontSize;
WordDocument.Tables.Item(i).Cell(2,1).Range.Text := '对应表名';
SetFontSize;
WordDocument.Tables.Item(i).Cell(2,2).Range.Text := ADOQuery2.FieldByName('TableName').AsString;
SetFontSize;
WordDocument.Tables.Item(i).Cell(3,1).Range.Text := 'ID号';
SetFontSize;
WordDocument.Tables.Item(i).Cell(3,2).Range.Text := ADOQuery1.FieldByName('ID').AsString;
SetFontSize;
WordDocument.Tables.Item(i).Cell(5,1).Range.Text := '字段名';
SetFontSize;
WordDocument.Tables.Item(i).Cell(5,2).Range.Text := '中文名称';
SetFontSize;
WordDocument.Tables.Item(i).Cell(5,3).Range.Text := '是否系统生成';
SetFontSize;
WordDocument.Tables.Item(i).Cell(5,4).Range.Text := '是否必填字段';
SetFontSize;
while not ADOQuery2.Eof do
begin
WordDocument.Tables.Item(i).Cell(j,1).Range.Text:=ADOQuery2.FieldByName('columnname').AsString;
SetFontSize;
WordDocument.Tables.Item(i).Cell(j,2).Range.Text:=ADOQuery2.FieldByName('discription').AsString;
SetFontSize;
j:=j+1;
ADOQuery2.Next;
end;
ADOQuery1.Next;
i:=i+1;
end;
except
on E: Exception do
begin
ShowMessage(E.Message);
WordApplication.Disconnect;
end;
end;
end;
end;end.