📄 u_msword.pas
字号:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.SetCaption(Value: String);
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Caption:=Value;
end;
{ **************************************************************************************
过程中文名称:取得WORD服务器的可见性
功能说明: 取得WORD服务器的可见性
参数说明:
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.GetVisible: Boolean;
begin
Result:=False;
if VarType(FWordApp)<>varDispatch then exit;
Result:=FWordApp.visible;
end;
//设置当前激活的WORD文档
procedure TWordObject.Set_ActiveDocument(const Value: OleVariant);
begin
end;
//取得当前激活的WORD文档
function TWordObject.Get_ActiveDocument: OleVariant;
begin
end;
procedure TWordObject.Set_Font(Value: TFont);
begin
if VarType(FWordApp)<>varDispatch then exit;
FFont.Assign(Value);
if fsBold in value.Style then
FWordApp.Selection.Font.Bold:=True
else
FWordApp.Selection.Font.Bold:=False;
end;
{ **************************************************************************************
过程中文名称:输出文本到WORD文件
功能说明: 输出文本到WORD文件
参数说明: Text 要输出的文字
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.InsertText(Const Text: String);
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.TypeText(Text);
end;
{ **************************************************************************************
过程中文名称:在当前WORD文档上输出一个回车换行符
功能说明: 在当前WORD文档上输出一个回车换行符
参数说明:
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.TypeParagraph;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.TypeParagraph;
end;
//向前回退的次数
Procedure TWordObject.set_ListOutDent(OutDentCount:Integer);
var
i:integer;
begin
if VarType(FWordApp)<>varDispatch then exit;
for i:=1 to OutDentCount do
FWordApp.Selection.Range.ListFormat.ListOutdent;
end;
//向后缩进的次数
Procedure TWordObject.Set_ListIndent(IndentCount:Integer);
var
i:integer;
begin
if VarType(FWordApp)<>varDispatch then exit;
for i:=1 to IndentCount do
FWordApp.Selection.Range.ListFormat.ListIndent;
end;
{ **************************************************************************************
过程中文名称:按指定字符数向后缩进
功能说明: 按指定字符数向后缩进
参数说明: IndentCount 缩进的字符数
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
Procedure TWordObject.LeftIndent(Const IndentCount:Integer);
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.ParagraphFormat.LeftIndent:=IndentCount*IndentUnitePoint;
end;
Function TWordObject.Find(FindString:String):Boolean;
begin
//服务没启动则不查找
if VarType(FWordApp)<>varDispatch then
begin
result:=False;
exit;
end;
if FWordApp.Selection.Find.Execute(FindText:=FindString,MatchCase:=True,
MatchWholeWord:=False,MatchWildcards:=False,
MatchSoundsLike:=False,MatchAllWordForms:=False,
Forward:=True, Wrap:=wdFindContinue,Format:=False,
ReplaceWith:='',Replace:=wdReplaceNone) then
Result:=true
else
result:=False;
end;
{ **************************************************************************************
过程中文名称:替换文本
功能说明: 替换文本
参数说明: FindString, 要查新替换的文字
ReplaceWithString 要替换得的文字
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
Procedure TWordObject.Replace(FindString,ReplaceWithString:String);
begin
//服务没启动则不替换
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.Find.Execute(FindText:=FindString,MatchCase:=True,
MatchWholeWord:=False,MatchWildcards:=False,
MatchSoundsLike:=False,MatchAllWordForms:=False,
Forward:=True, Wrap:=wdFindContinue,Format:=False,
ReplaceWith:=ReplaceWithString,Replace:=wdReplaceAll);
end;
{ **************************************************************************************
过程中文名称:新建一页
功能说明: 新建一页
参数说明:
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.NewPage;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.Movedown(Unit:=wdLine, Count:=1,Extend:=0);
FWordApp.Selection.HomeKey(Unit:=wdLine,Extend:=0);
FWordApp.Selection.InsertBreak(wdSectionBreakNextPage);
end;
{ **************************************************************************************
过程中文名称:在指定字串处插入一页
功能说明: 在指定字串处插入一页
参数说明: PageBreakIDen //指定的字串
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.NewPage(Const PageBreakIDen: String);
var
FindIden :Boolean;
begin
if VarType(FWordApp)<>varDispatch then exit;
FindIden:=True;
While FindIden do
begin
FindIden:= FWordApp.Selection.Find.Execute(FindText:=PageBreakIDen,MatchCase:=True,
MatchWholeWord:=False,MatchWildcards:=False,
MatchSoundsLike:=False,MatchAllWordForms:=False,
Forward:=True, Wrap:=wdFindStop,Format:=False,
ReplaceWith:='',Replace:=wdReplaceNone);
if FindIden then
begin
FWordApp.Selection.Movedown(Unit:=wdLine, Count:=1,Extend:=0);
FWordApp.Selection.HomeKey(Unit:=wdLine,Extend:=0);
FWordApp.Selection.InsertBreak(wdSectionBreakNextPage);
FWordApp.Selection.TypeParagraph;
FWordApp.Selection.HomeKey(Unit:=wdStory);
FWordApp.Selection.Find.Execute(FindText:=PageBreakIDen,MatchCase:=True,
MatchWholeWord:=False,MatchWildcards:=False,
MatchSoundsLike:=False,MatchAllWordForms:=False,
Forward:=True, Wrap:=wdFindStop,Format:=False,
ReplaceWith:='',Replace:=wdReplaceOne);
end;
end;
end;
{ **************************************************************************************
过程中文名称:新建一个WORD文档,并将其设为当前文档
功能说明: 新建一个WORD文档,并将其设为当前文档
参数说明:
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
Function TWordObject.NewDoc:OleVariant;
begin
if VarType(FWordApp)<>varDispatch then exit;
FCurrentDoc:=FWordApp.Documents.add;
Result:=FCurrentDoc;
end;
{ **************************************************************************************
过程中文名称:打印文件
功能说明: 打印文件
参数说明:
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.Print;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.PrintOut;
end;
{ **************************************************************************************
过程中文名称:将当前的文档保存
功能说明: 将当前的文档保存
参数说明:
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.Save;
begin
if VarType(FWordApp)<>varDispatch then exit;
FCurrentDoc.Save;
end;
{ **************************************************************************************
过程中文名称:将当前的文档保存为指定的文件名称
功能说明: 将当前的文档保存为指定的文件名称
参数说明: Filename 要保存为的文件名称
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.DocumentSaveAs(const Filename: String);
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.ActiveDocument.SaveAs(FileName,wdFormatDocument);
end;
{ **************************************************************************************
过程中文名称:设置WORD服务程序的可见性
功能说明: 设置WORD服务程序的可见性
参数说明: Value 可见与否
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.SetVisible(Value: Boolean);
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Visible:=Value;
end;
{ **************************************************************************************
过程中文名称:返回指定名称的worddocument变量
功能说明: 返回指定名称的worddocument变量
参数说明: FileName :文件名称
MS_Document : 返回的WORD文件名称
返加值: 有指定名文件打开,返回真
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.Get_WordDoCument(Const FileName: string;
var MS_Document: OleVariant): Boolean;
var
i :integer;
DocCount :integer;
begin
if FbConnect then
begin
DocCount:=FWordApp.Documents.Count;
For i:=1 to DocCount do
begin
if FWordApp.Documents.Item(i).FullName=FileName then
begin
MS_Document:=FWordApp.Documents.Item(i);
FCurrentDoc:=MS_Document;
Result:=true;
exit;
end;
end;
end;
Result:=False;
end;
{ **************************************************************************************
过程中文名称:返回指定名称是否存在
功能说明: 返回指定名称是否存在
参数说明: FileName :文件名称
返加值: 有指定名文件打开,返回真
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.Get_WordDoCument(Const FullFileName: String): Boolean;
var
i : integer;
begin
if FbConnect then
begin
For i:=1 to FWordApp.Documents.Count do
begin
if FWordApp.Documents.Item(i).FullName=FullFileName then
begin
FCurrentDoc:=FWordApp.Documents.Item(i);
Result:=true;
exit;
end;
end;
end;
Result:=False;
end;
{ **************************************************************************************
过程中文名称: 检查是否在表格中
功能说明: 检查是否在表格中
参数说明:
返加值: 在表格中,返回TRUE
否则返回False
最初编写日期:2004-3-12
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.isInTables: Boolean;
begin
if VarType(FWordApp)<>varDispatch then
begin
Result:=False;
exit;
end;
if IsCell(FWordApp.Selection) then
begin
Result:=True;
end
else
begin
Result:=False;
end;
end;
{ **************************************************************************************
过程中文名称:判断光标所在的位置是否为表
功能说明: 判断光标所在的位置是否为表
如果选择点表表格数为0则不在表格中
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -