怎么在Word里画表格?

032031121 2004-09-18 01:06:25
怎么在Word里画表格?
...全文
7063 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
YOHOYOHO 2004-09-18
  • 打赏
  • 举报
回复
chinaliujacky(失落之城)
可爱了。。。。
chinaliujacky 2004-09-18
  • 打赏
  • 举报
回复
那你就在菜单里找‘表格-插入-表格’就行了,你到底在想什么?难道用DELPHI在WORD里画表吗?
pengxuan 2004-09-18
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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;

implementation

uses 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.
WGYKING 2004-09-18
  • 打赏
  • 举报
回复
老兄
怎么加分了啊

^_^
WGYKING 2004-09-18
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3370/3370314.xml?temp=.9221002
代码里有简单的画表格

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧