我全的例子,给你作参考
newword.documents.add(Template:='f:\mynew.ttk.dot');
newword.selection.GoTo(what:=3,count:=11);
newword.selection.endkey;
activerow:=newword.activedocument.Paragraphs.count;
s:='第三学年 上学期'+form1.StatusBar1.Panels[0].Text+'试卷';
newword.activedocument.paragraphs.item(activerow).range.text:=s;
newword.selection.endkey;
newword.Selection.MoveLeft(Count:=length(s)/2, Extend:=1);
newword.Selection.Font.Size:= 16;
newword.Selection.ParagraphFormat.Alignment:=1;
newword.Selection.Font.Bold:= true;
newword.selection.endkey;
newword.selection.InsertFile(FileName:='f:\headk.doc');
ztjd.ProgressBar1.Position:=10;
ztjd.label2.Caption:='10'+'%';
ztjd.Update;
newword.Selection.ParagraphFormat.Alignment:=0;
newword.Selection.Font.Size:= 10;
newword.Selection.Font.Bold:= false;
newword.selection.endkey;
//*************************************//试卷题头end
jd:=0;
for i:=0 to listview3.Items.Count-1 do//从数组往word中写数据
begin
tzb:=strtoint(listview3.items[i].SubItems[0])*90 div maxnum;
zttj:='(';
jd:=jd+strtoint(listview3.Items[i].SubItems[0]);//增加jd
for j:=jd-strtoint(listview3.Items[i].SubItems[0]) to jd-1 do//读当前题型
zttj:=zttj+inttostr(maxtxnum[j])+',';//循环
zttj:=copy(zttj,1,length(zttj)-1)+')';
with clientdataset3 do//打开所抽题库
begin
close;
commandtext:='select * from tk_lr where tid in '+zttj;
open;
end;//打开所抽题库end
//开始读库写卷*****************************
newword.selection.InsertFile(FileName:='f:\kuang.ttk');
xth:=1;
activerow:=newword.activedocument.Paragraphs.count;
newword.activedocument.paragraphs.item(activerow-1).range.text:=listview3.Items[i].Caption;
newword.activedocument.paragraphs.add;
ztjd.ProgressBar1.Position:=ztjd.ProgressBar1.Position+tzb*10 div 100;
ztjd.label2.Caption:=inttostr(ztjd.ProgressBar1.Position)+'%';
ztjd.Update;
newword.selection.movedown;
with clientdataset3 do
begin
while not eof do
begin
ztjd.ProgressBar1.Position:=ztjd.ProgressBar1.Position+tzb*90*recno div recordcount div 100;
ztjd.Label2.Caption:=inttostr(ztjd.ProgressBar1.Position)+'%';
ztjd.Update;
mystream:=createblobstream(clientdataset3lr,bmread);
olecontainer1.LoadFromStream(mystream);
olecontainer1.SaveAsDocument('f:\mytt.ttk');
activerow:=newword.activedocument.Paragraphs.count;
newword.activedocument.paragraphs.item(activerow).range.text:=inttostr(xth)+'、';
newword.selection.endkey;
newword.selection.InsertFile(FileName:='f:\mytt.ttk');
next;
xth:=xth+1;
end;
end;
//结束读库写卷*****************************
end;
screen.Cursor:=crdefault;
ztjd.free;
if checkbox1.Checked then//存入本地硬盘
if SaveDialog1.Execute then
begin
newword.activedocument.saveas(filename:=savedialog1.FileName);
if messagebox(form9.handle,'试题已存入本地硬盘!','信息窗口',mb_ok)=1 then
newword.activedocument.close;
end;
if checkbox2.Checked then messagebox(form9.handle,'试题已存入网络服务器!','信息窗口',mb_ok);//网络服务器
newword.documents.add(Template:='f:\mynew.ttk.dot');
newword.selection.GoTo(what:=3,count:=11);
newword.selection.endkey;
activerow:=newword.activedocument.Paragraphs.count;
s:='第三学年 上学期'+form1.StatusBar1.Panels[0].Text+'试卷';
newword.activedocument.paragraphs.item(activerow).range.text:=s;
newword.selection.endkey;
newword.Selection.MoveLeft(Count:=length(s)/2, Extend:=1);
newword.Selection.Font.Size:= 16;
newword.Selection.ParagraphFormat.Alignment:=1;
newword.Selection.Font.Bold:= true;
newword.selection.endkey;
newword.selection.InsertFile(FileName:='f:\headk.doc');
ztjd.ProgressBar1.Position:=10;
ztjd.label2.Caption:='10'+'%';
ztjd.Update;
newword.Selection.ParagraphFormat.Alignment:=0;
newword.Selection.Font.Size:= 10;
newword.Selection.Font.Bold:= false;
newword.selection.endkey;
//*************************************//试卷题头end
jd:=0;
for i:=0 to listview3.Items.Count-1 do//从数组往word中写数据
begin
tzb:=strtoint(listview3.items[i].SubItems[0])*90 div maxnum;
zttj:='(';
jd:=jd+strtoint(listview3.Items[i].SubItems[0]);//增加jd
for j:=jd-strtoint(listview3.Items[i].SubItems[0]) to jd-1 do//读当前题型
zttj:=zttj+inttostr(maxtxnum[j])+',';//循环
zttj:=copy(zttj,1,length(zttj)-1)+')';
with clientdataset3 do//打开所抽题库
begin
close;
commandtext:='select * from tk_lr where tid in '+zttj;
open;
end;//打开所抽题库end
//开始读库写卷*****************************
newword.selection.InsertFile(FileName:='f:\kuang.ttk');
xth:=1;
activerow:=newword.activedocument.Paragraphs.count;
newword.activedocument.paragraphs.item(activerow-1).range.text:=listview3.Items[i].Caption;
newword.activedocument.paragraphs.add;
ztjd.ProgressBar1.Position:=ztjd.ProgressBar1.Position+tzb*10 div 100;
ztjd.label2.Caption:=inttostr(ztjd.ProgressBar1.Position)+'%';
ztjd.Update;
newword.selection.movedown;
with clientdataset3 do
begin
while not eof do
begin
ztjd.ProgressBar1.Position:=ztjd.ProgressBar1.Position+tzb*90*recno div recordcount div 100;
ztjd.Label2.Caption:=inttostr(ztjd.ProgressBar1.Position)+'%';
ztjd.Update;
mystream:=createblobstream(clientdataset3lr,bmread);
olecontainer1.LoadFromStream(mystream);
olecontainer1.SaveAsDocument('f:\mytt.ttk');
activerow:=newword.activedocument.Paragraphs.count;
newword.activedocument.paragraphs.item(activerow).range.text:=inttostr(xth)+'、';
newword.selection.endkey;
newword.selection.InsertFile(FileName:='f:\mytt.ttk');
next;
xth:=xth+1;
end;
end;
//结束读库写卷*****************************
end;
screen.Cursor:=crdefault;
ztjd.free;
if checkbox1.Checked then//存入本地硬盘
if SaveDialog1.Execute then
begin
newword.activedocument.saveas(filename:=savedialog1.FileName);
if messagebox(form9.handle,'试题已存入本地硬盘!','信息窗口',mb_ok)=1 then
newword.activedocument.close;
end;
if checkbox2.Checked then messagebox(form9.handle,'试题已存入网络服务器!','信息窗口',mb_ok);//网络服务器
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货