DelphiWord格式.docx
《DelphiWord格式.docx》由会员分享,可在线阅读,更多相关《DelphiWord格式.docx(19页珍藏版)》请在冰豆网上搜索。
proceduresettableback(backcolor:
toleenum);
//鼠标下移
proceduremovedown(num:
integer=1);
//选择下移
procedureselectdown(num:
//鼠标上移
proceduremoveup();
//鼠标右移
proceduremoveright(num:
//选择右移
procedureselectright(num:
//写字
procedurewritetext(text:
string);
//按样式插入一行记录
//如addline"
备注"
"
正文"
//addline'
kk'
标题1"
procedureaddline(s:
pstyle:
olevariant);
procedurealignline(align:
//插入分页符
procedureinsertpage();
//插入插入页码
procedureinsertpagenum();
//插入日期
procedureinsertdate();
//设置表格一列宽度
proceduresettable(ptable:
columnidx:
width:
integer);
//设置表格一列高度
proceduresettableheight(ptable:
rowidx:
height:
//插入目录
procedureinsertcontents();
//创立书签
procedurecreatebookmark(bookmarkname:
//移动到标签
proceduregotobookmark(bookmarkname:
//粘贴
procedurepaste();
//替换
procedurereplace(source,target:
//保存
proceduresave(filename:
//插入图片
procedureaddpicture(filename:
//移到最后
proceduremoveend();
//合并
procedurecellsmerge();
constructorcreate;
destructordestroy;
override;
end;
//functionmyword:
tmyword;
implementation
//var
//
fmyword:
{functionmyword:
begin
iffmyword=nilthen
begin
fmyword:
=tmyword.create;
end;
result:
=fmyword;
}
constructortmyword.create();
inheritedcreate;
connectword();
//
proceduretmyword.connectword();
var
b:
boolean;
b:
=false;
if(fword=nil)then
=true
else
try
fdoc.activate;
except
=true;
ifnotbthenexit;
fword:
=twordapplication.create(nil);
fdoc:
=tworddocument.create(nil);
//文档对象
fword.connect;
fword.visible:
destructortmyword.destroy;
//fdoc.saveas('
c:
\1.doc'
);
fdoc.free;
fword.disconnect;
//退出一定退出word,byyl2005.2.2
//fword.quit;
//fword.free;
inheriteddestroy;
proceduretmyword.addreturn();
fword.selection.typeparagraph;
addreturn();
proceduretmyword.setfont(fontname:
boolean
//connectword();
fword.selection.font.name:
=fontname;
fword.selection.font.size:
=fontsize;
iffontboldthen
fword.selection.font.bold:
=wdtoggle;
iffontunderlinethen
fword.selection.font.underline:
=wdunderlinesingle;
setfont(fontname,fontsize,fontbold,fontunderline);
//插入表格
functiontmyword.addtable(col,row:
defaulttable:
olevariant;
defaulttable:
=1;
=fdoc.tables.add(fword.selection.range,row,col,defaulttable,
emptyparam);
showmessage(format('
列%d,行%d'
[col,row]));
addtable(col,row);
//设置背景色
proceduretmyword.settableback(backcolor:
fword.selection.cells.shading.backgroundpatterncolor:
=backcolor;
settableback(backcolor);
//选择下移
proceduretmyword.selectdown(num:
unit_:
count:
extend:
count:
=num;
unit_:
=wdline;
extend:
=wdextend;
fword.selection.movedown(unit_,count,extend);
movedown();
//鼠标下移
proceduretmyword.movedown(num:
//鼠标上移
proceduretmyword.moveup();
fword.selection.moveup(unit_,count,extend);
//选择右移
proceduretmyword.selectright(num:
=wdcharacter;
fword.selection.moveright(unit_,count,extend);
moveright();
//鼠标右移
proceduretmyword.moveright(num:
=wdcell;
//写字
proceduretmyword.writetext(text:
fword.selection.typetext(text);
except
//防止呼叫失败
writetext(text);
//按样式插入一行记录
//如addline"
//addline'
proceduretmyword.addline(s:
proceduresetstyle(pstyle:
outstyle:
style;
v:
outstyle:
=fword.activedocument.styles.item(pstyle);
v:
=outstyle;
fword.selection.set_style(v);
writetext(s);
//加入一行
setstyle(pstyle);
proceduretmyword.alignline(align:
fword.selection.paragraphformat.alignment:
=align;
//插入分页符
proceduretmyword.insertpage();
_type:
_type:
=7;
fword.selection.insertbreak(_type);
//插入日期
proceduretmyword.insertdate();
datetimeformat:
insertasfield:
insertasfullwidth:
datelanguage:
calendartype:
insertasfield:
insertasfullwidth:
datetimeformat:
='
yyyy'
'
年'
m'
月'
d'
日'
;
datelanguage:
=wdsimplifiedchinese;
calendartype:
=wdcalendarwestern;
fword.selection.insertdatetime(datetimeformat,insertasfield,
insertasfullwidth,datelanguage,calendartype);
insertdate();
//插入页码
proceduretmyword.insertpagenum();
psection:
section;
pagenumberalignment:
firstpage:
psection:
=fword.selection.sections.item
(1);
pagenumberalignment:
//中间
firstpage:
psection.footers.item(wdheaderfooterprimary).pagenumbers.add(pagenumberalignment,firstpage);
//设置表格一列高度
proceduretmyword.settableheight(ptable:
integer);
prow:
row;
prow:
=ptable.rows.item(rowidx);
prow.setheight(height,wdadjustnone);
//设置表格一列宽度
proceduretmyword.settable(ptable:
ptable.columns.item(columnidx).setwidth(width,wdadjustnone);
//插入目录
proceduretmyword.insertcontents();
prange:
range;
useheadingstyles:
upperheadinglevel:
lowerheadinglevel:
usefields:
tableid:
rightalignpagenumbers:
includepagenumbers:
addedstyles:
usehyperlinks:
hidepagenumbersinweb:
withfword.activedocumentdo
prange:
=fword.selection.range;
rightalignpagenumbers:
useheadingstyles:
upperheadinglevel:
lowerheadinglevel:
=3;
includepagenumbers:
usehyperlinks:
hidepagenumbersinweb:
tablesofcontents.add(prange,useheadingstyles,
upperheadinglevel,
lowerheadinglevel,
usefields,
tableid,
rightalignpagenumbers,
includepagenumbers,
addedstyles,usehyperlinks,
hidepagenumbersinweb);
tablesofcontents.item
(1).tableader:
=wdtableaderdots;
tablesofcontents.format:
=wdindexindent;
//创立书签
proceduretmyword.createbookmark(bookmarkname:
withfword.activedocument.bookmarksdo
add(bookmarkname,prange);
defaultsorting:
=wdsortbyname;
showhidden:
//移动到标签
proceduretmyword.gotobookmark(bookmarkname:
what:
which:
name:
what:
=wdgotobookmark;
name:
begin'
fword.selection.goto_(what,
which,
count,
name)
//粘贴
proceduretmyword.paste();
fword.selection.paste;
//替换
proceduretmyword.replace(source,target:
findtext:
pwrap:
replacewith:
replace:
fword.selection.find.clearformatting;
fword.selection.find.replacement.clearformatting;
findtext:
=source;
pwrap:
=wdfindcontinue;
replacewith:
=target;
replace:
=wdreplaceall;
withfword.selection.finddo
{text:
replacement.