如何将文字及图片插入word文件

lionsoft 2007-10-19 03:03:06
如何将文字及图片插入word文件
...全文
1137 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
y8802 2007-10-24
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure InsertLines(LineNum:Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
wordApp,wordDoc:Variant;
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses ComObj;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
StrAdd:String;
i:Integer;
wrdSelection:Variant;
begin
//创建一个word对象
wordApp:=CreateOleObject('Word.Application');
wordApp.Visible:=true;
//创建一个word文档
wordDoc:=wordApp.Documents.Add();
wordDoc.Select;

wrdSelection:=wordApp.selection;

//在文档中插入内容
StrAdd:='插入一张图片';
wrdSelection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
wrdSelection.font.bold:=true;
wrdSelection.font.size:=15;
wrdSelection.font.Underline:=1;
wrdSelection.TypeText(StrAdd);

wrdSelection.font.Underline:=0;
wrdSelection.font.bold:=false;
wrdSelection.font.size:=11;
InsertLines(1);

//在文档中插入一个4行4列的表格,并格式化
wordDoc.Tables.Add(wrdSelection.Range,4,4,2,0);
wordDoc.Tables.Item(1).Borders.Item(1).LineStyle:=7;
wordDoc.Tables.Item(1).Borders.Item(2).LineStyle:=7;
wordDoc.Tables.Item(1).Borders.Item(3).LineStyle:=7;
wordDoc.Tables.Item(1).Borders.Item(4).LineStyle:=7;
for i:=1 to 4 do
begin
wordDoc.Tables.Item(1).Cell(i,1).Range.Bold:=true;
wordDoc.Tables.Item(1).Cell(i,3).Range.Bold:=true;
wordDoc.Tables.Item(1).Rows.Item(i).Range.Paragraphs.Alignment:=wdAlignParagraphCenter;
end;
//在第一个表格中插入内容
wordDoc.Tables.Item(1).Cell(1,1).Range.text:='岗位名称';
worddoc.tables.item(1).cell(1,2).range.InlineShapes.AddPicture('E:\heartsong\0003.gif',False,True);//这就是加放入图片的语句
wordDoc.Tables.Item(1).Cell(2,1).Range.InsertAfter('岗位级别');
wordDoc.Tables.Item(1).Cell(3,1).Range.InsertAfter('隶属部门');
wordDoc.Tables.Item(1).Cell(4,1).Range.InsertAfter('直接上级');
wordDoc.Tables.Item(1).Cell(1,3).Range.InsertAfter('岗位编号');
wordDoc.Tables.Item(1).Cell(2,3).Range.InsertAfter('现任职者');
wordDoc.Tables.Item(1).Cell(3,3).Range.InsertAfter('分支机构');
wordDoc.Tables.Item(1).Cell(4,3).Range.InsertAfter('直接下级');

//保存文档

......
end;

end.
buding79 2007-10-24
  • 打赏
  • 举报
回复
插入图片:
var
WinWord,WordHandle:variant;
begin
WinWord:=CreateOleObject( 'Word.Application ');
WinWord.visible:=True;
WordHandle:=WinWord.Documents.Add(Template:= ' ',NewTemplate:=False);
WinWord.Selection.InlineShapes.AddPicture(FileName:= 'f:\Adobe1.jpg ',
LinkToFile:=False,SaveWithDocument:=True);

winword.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
end;
oushengfen 2007-10-24
  • 打赏
  • 举报
回复
以上楼主的方法都可以.就看你怎么使用了.
shuiwencai 2007-10-19
  • 打赏
  • 举报
回复
delphi里有个demo,专门介绍将数据库内容插入到WORD,很详细,自己看看就会了
ziping 2007-10-19
  • 打赏
  • 举报
回复
TBOLDFIELD类型
lionsoft 2007-10-19
  • 打赏
  • 举报
回复
最好控件说明及代码

5,931

社区成员

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

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