Delphi中输入的数据填入Word表格中?

在Delphi中输入的数据填入Word表格中,比如把EDIT的录入信息输入Word的第一列的第二格中,怎么做?代码和组件要哪些?希望各大虾给详细的做法,定重谢!在线等啊!... 在Delphi中输入的数据填入Word表格中,比如把EDIT的录入信息输入Word的第一列的第二格中,怎么做?代码和组件要哪些?希望各大虾给详细的做法,定重谢!在线等啊!拜托了!
能简化下么,比图,一个做好的3*3的WORD表格,如何把数据填进去呢?
展开
 我来答
aknba2009
2010-05-23 · TA获得超过3403个赞
知道大有可为答主
回答量:609
采纳率:0%
帮助的人:639万
展开全部
给你个delphi操作word表格的例子,研究一下,可以达到你的要求:

Delphi与Word例1

//================== Word_VBA 代码 ====================//
sub inWord()
Dim myTable As Table
Dim myBox, myPict, myShape As Shape

'画第一个矩形框
Set myBox = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=90, Top:=70, Width:=414, Height:=200)

'画一条竖线
Set myLine = ActiveDocument.Shapes.AddLine(255, 70, 255, 270)

'画第一幅图
Set myPict = ActiveDocument.Shapes.AddPicture("D:\test\test\load_jpg1\photo\108259.jpg", _
LinkToFile:=False, SaveWithDocument:=True, Left:=180, Top:=80, Width:=65, Height:=80)

'画第二幅图
Set myPict = ActiveDocument.Shapes.AddPicture("D:\test\test\load_jpg1\photo\108259.jpg", _
LinkToFile:=False, SaveWithDocument:=True, Left:=262, Top:=80, Width:=65, Height:=80)

'姓名
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=198, Width:=126, Height:=18)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "姓名:新之助"

'年龄
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=225, Width:=126, Height:=18)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "年龄:12"

'个人信息
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=351, Top:=90, Width:=126, Height:=99)
myShape.Line.Visible = msoFalse
myShape.TextFrame.TextRange.Text = "个人信息"

'文本框中添加表格
Set myShape = ActiveDocument.Shapes.AddTextbox(Orientation:=1, Left:=288, Top:=198, Width:=189, Height:=63)
myShape.Line.Visible = msoFalse

Set myTable = ActiveDocument.Tables.Add(Range:=myShape.TextFrame.TextRange, NumRows:=3, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed)
myTable.Cell(1, 1).Range.Text = "体重"
myTable.Cell(1, 2).Range.Text = "40kg"
myTable.Cell(2, 1).Range.Text = "身高"
myTable.Cell(2, 2).Range.Text = "120cm"
myTable.Cell(3, 1).Range.Text = "坐高"
myTable.Cell(3, 2).Range.Text = "65cm"
end sub
//================== Delphi代码 ====================//
procedure inDelphi;
var
WordApp,WordDoc,WordTable,wordShape:OleVariant; // se:Selection;
filename:string;
begin
SaveDialog1.InitialDir:=ExtractFilePath(Application.ExeName)+'out_file';
SaveDialog1.Execute;
self.Refresh;
filename:=savedialog1.FileName;
if length(filename)=0 then
begin
application.MessageBox(' 没有选择统计文件的存储位置,不能保存统计的数据! ','提示框',mb_ok);
exit;
end;
WordApp:=CreateOleObject('Word.Application');
WordApp.Visible:=True;
WordDoc:=WordApp.Documents.Add;
try

//画第一个矩形框
worddoc.SHAPES.AddTextbox(Orientation:=1, Left:=90, Top:=70, Width:=414, Height:=200);
//画一条竖线
worddoc.Shapes.AddLine(255, 70, 255,270);
//画第一幅图
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo\108259.jpg',
LinkToFile:=False, SaveWithDocument:=True, Left:=180, Top:=80, Width:=65, Height:=80);
//画第二幅图
worddoc.SHAPES.addpicture(ExtractFilePath(Application.ExeName)+'photo\108259.jpg',
LinkToFile:=False, SaveWithDocument:=True, Left:=262, Top:=80, Width:=65, Height:=80);

//画 姓名 框
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=198, Width:=126, Height:=18);
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := '姓名:新之助';
//年龄 框
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=108, Top:=225, Width:=126, Height:=18);//.Select;
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := '年龄:12';
//个人信息 框
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=351, Top:=90, Width:=126, Height:=99);//.Select;
wordShape.Line.Visible := false;
wordShape.TextFrame.TextRange.Text := '个人信息';
//文本框中添加表格
wordShape:=worddoc.Shapes.AddTextbox(Orientation:=1, Left:=288, Top:=198, Width:=189, Height:=63);//.Select;
wordShape.Line.Visible := false;
WordTable := worddoc.Tables.Add(Range:=wordShape.TextFrame.TextRange, NumRows:=3, NumColumns:=2,
DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:=wdAutoFitFixed);
WordTable.Cell(1, 1).Range.Text := '体重';
WordTable.Cell(1, 2).Range.Text := '40kg';
WordTable.Cell(2, 1).Range.Text := '身高';
WordTable.Cell(2, 2).Range.Text := '120cm';
WordTable.Cell(3, 1).Range.Text := '坐高';
WordTable.Cell(3, 2).Range.Text := '65cm';

WordDoc.saveas(filename);
application.MessageBox(' 输出成功! ','提示框',mb_ok);

finally
WordDoc.Saved:=true;
WordDoc.Close;
WordApp.Quit;
end;

end;
cb120520025
2010-05-23 · TA获得超过347个赞
知道小有建树答主
回答量:323
采纳率:0%
帮助的人:580万
展开全部
//运行前先关闭所有的Word

uses WordXP;

var
wa :TWordApplication;
wd :TWordDocument;
ItemIndex,FileName,Saves :OleVariant;
begin
wa := TWordApplication.Create(nil);
wd := TWordDocument.Create(nil);
try
wa.Connect;
FileName := 'd:\temp1.doc'; //指定文件的位置
ItemIndex := FileName;
wa.Documents.Open(FileName,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
wd.ConnectTo(wa.Documents.Item(ItemIndex));
wa.Options.CheckSpellingAsYouType := False;
wa.Options.CheckGrammarAsYouType := False;
wd.Tables.Item(1).Cell(2,1).Range.Text := Edit1.Text; //指定要写入数据的表格和单元格
wd.SaveAs(FileName);
ShowMessage('写入Word成功');
except
ShowMessage('写入Word失败');
end;
wd.Close(Saves);
wd.Disconnect;
wa.Quit(Saves);
wa.Disconnect;
FreeAndNil(wd);
FreeAndNil(wa);
end;
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式