使用Delphi控制Word的图片排版(40分)

  • 主题发起人 virtualmfc
  • 开始时间
V

virtualmfc

Unregistered / Unconfirmed
GUEST, unregistred user!
本人想使用Delphi与Word 2000交互使用,欲将Access数据库中的记录写入到Word 2000中进行排版。文字问题已解决,但是在处理图片时出现
一点问题。即我是通过TWordApplication来操纵Word,并使用WordApplication.Document.Shapes.AddPicture来处理,但发现图片都挤在一块,
不能按格式排列。请问如何象一般Word处理一样有规律地排列。格式要求如下:

图片
公司名称
公司地址

图片
公司名称
公司地址
 
应该和文字一样处理吧!
 
我现在也在做这个方面的,我从来没有做过类似的程序,能不能发一段你的代码过来看看
我做的一个也是跟你这个类似的,不过我的是一行有两个这样的。如:
姓名 姓名
学号 学号
照片 照片

能不能发你的代码过来看看。谢谢
我的EMAIL:xgr541@163.com
 
将文档中设定一个书签,将图片插入书签的位置,搞定
 
能不能写一小段试验代码贴上来看看。
 
我写好了能控制EXCEL的程序了.
 
我用EXCEL做出来了一点。反正是满足了我自己的要求了。
procedure TFrmMain.CET6Click(Sender: TObject);
var
ExcelApp: Variant;
selection:variant;
aSheet: variant;
i:integer;
zkzno:string;
picstr:string;
fpath,fpath1:string;
errcount:integer;
xuehao:string;
begin
ExcelApp := CreateOleObject('Excel.Application' );
ExcelApp.Visible := True;
ExcelApp.Caption := 'Microsoft Excel--打印';
fpath:=extractfiledir(application.ExeName);
ExcelApp.WorkBooks.Add(fpath+'/demo.xls');
excelapp.activesheet.columns[3].columnwidth:=0.5; //设置间隔
i:=0;
errcount:=0;
fpath:=fpath+'/StuPic/';

adoquerycet6.First;
while not adoquerycet6.Eof do begin

//***************************************************************//
excelapp.worksheets[1].range['A'+inttostr(2+i),'A'+inttostr(2+i)].select;
asheet:=excelapp.activesheet;
//提取照片,如果为空的话,则采用jm.jpg。
xuehao:=adoquerycet6.fieldbyname('xuehao').asstring;
picstr:=fpath+xuehao+'.jpg';
if copy(picstr,length(picstr)-4,5)='/.jpg' then begin
picstr:=fpath+'jm.jpg';
errcount:=errcount+1;
end;
selection:=asheet.pictures.insert(picstr).select;
//照片缩放30%
excelapp.selection.ShapeRange.Height:= 89.25;
excelapp.Selection.ShapeRange.Width := 67.5;
Excelapp.worksheets[1].range['A'+inttostr(1+i),'B'+inttostr(1+i)].merge(emptyparam);
excelapp.worksheets[1].Range['A'+inttostr(1+i),'B'+inttostr(1+i)].HorizontalAlignment:=xlcenter;
Excelapp.worksheets[1].range['A'+inttostr(8+i),'B'+inttostr(8+i)].merge(emptyparam);
Excelapp.worksheets[1].range['A'+inttostr(2+i),'A'+inttostr(7+i)].merge(emptyparam);
Excelapp.worksheets[1].Range['A'+inttostr(2+i),'A'+inttostr(2+i)].ColumnWidth:=10.75;
Excelapp.worksheets[1].Range['B'+inttostr(2+i),'B'+inttostr(2+i)].ColumnWidth:=28.63;
ExcelApp.Cells[1+i,1].Value := '大学英语四级考试CET-4';
ExcelApp.Cells[2+i,2].Value := '学校:东华理工学院';
ExcelApp.Cells[3+i,2].Value := '院系:'+adoquerycet6.fieldbyname('xi').asstring;
zkzno:=adoquerycet6.fieldbyname('zhunkaozheng').asstring;
ExcelApp.Cells[4+i,2].Value := '考试地点:210教室第'+copy(zkzno,length(zkzno)-4+1,2)+'考场';
ExcelApp.Cells[5+i,2].Value := '准考证号:'+adoquerycet6.fieldbyname('zhunkaozheng').asstring;
ExcelApp.Cells[6+i,2].Value := '考生姓名:'+adoquerycet6.fieldbyname('xingming').asstring;
ExcelApp.Cells[7+i,2].Value := '考试时间:6月24日8:45-11:00';
ExcelApp.ActiveSheet.Rows[8+i].RowHeight := 0.65/0.035; // 1厘米
adoquerycet6.Next;
//***************************************************************//
i:=i+9; //本来为8,但空一行比较好.
adoquerycet6.Next;
end;
if errcount>0 then
showmessage('可能没有照片的有'+inttostr(errcount)+'个学生');
end;


 
当然在提取照片的时候,如果找不到的话,可以再加入一个判断语句就可以了.各位能不能实现在WORD中实现啊.我到现在还没有弄出来.[:(]
 
顶部