📄 u_msword.pas
字号:
参数说明: ASelection --光标所在的位置
返加值: 如果是表返回TRUE
如果不是表返回FALSE
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.IsCell(ASelection: OLEVariant): Boolean;
begin
if VarType(ASelection)<>varDispatch then
begin
Result:=False;
exit;
end;
{如果选择点表表格数为0则不在表格中}
if ASelection.Tables.Count<=0 then
begin
Result:=False;
end
else
begin
Result:=True;
end;
end;
{ **************************************************************************************
过程中文名称:返加当前的行号,及列号
功能说明: 返加当前的行号,及列号
参数说明: ACol, 列号行号
ARow: 列号行号
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
procedure TWordObject.Get_CurrColAndRow(var ACol, ARow: integer);
begin
if FWordApp.Selection.Information[wdWithInTable] = True then
begin
ACol:=FWordApp.Selection.Information[wdStartOfRangeColumnNumber];
ARow:=FWordApp.Selection.Information[wdStartOfRangeRowNumber];
end;
end;
{ **************************************************************************************
过程中文名称:返加当前的行数,及列数
功能说明: 返加当前的行数,及列数
参数说明: ACols, 列号行数
ARows: 列号行v号
返加值:
最初编写日期:2004-3-11
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.Get_CurrColsAndRows(var ACols,
ARows: integer): Boolean;
begin
try
Result:=false;
if FWordApp.Selection.Information[wdWithInTable] = True then
begin
ACols:=FWordApp.SelectionTables.Item(1).Cols.Count;
ARows:=FWordApp.Selection.Tables.Item(1).Rows.Count;
Result:=True;
end;
except
Result:=false;
end;
end;
{ **************************************************************************************
过程中文名称:返回当前在表格的行号
功能说明: 返回当前在表格的行号
参数说明:
返加值: 返回当前在表格的行号
最初编写日期:2004-6-10
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.Get_CurrRow: integer;
begin
Result:=-1;
if FWordApp.Selection.Information[wdWithInTable] = True then
begin
Result:=FWordApp.Selection.Information[wdStartOfRangeRowNumber];
end;
end;
{ **************************************************************************************
过程中文名称:返回表格的行数
功能说明: 返回表格的行数
参数说明:
返加值: 返回表格的行数
最初编写日期:2004-6-10
最初编写人: 李志文
*************************************************************************************** }
function TWordObject.Get_CurrRows: integer;
begin
Result:=0;
if FWordApp.Selection.Information[wdWithInTable] = True then
begin
Result:=FWordApp.Selection.Tables.Item(1).Rows.Count;
end;
end;
{
**************************************************************************************
过程中文名称:产生一表格
功能说明:产生一表格
参数说明:AMS_Table: 表格生成的表格
ACols, 列数
ARows: 行数
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.AddNewTable(Const AMS_Document: OLEVariant;
var AMS_Table: OLEVariant; const ACols,
ARows: integer);
begin
if VarType(FWordApp)<>varDispatch then exit;
AMS_Table:=AMS_Document.Tables.Add(Range:=FWordApp.Selection.Range,
NumRows:=ARows,NumColumns:=ACols);
AMS_Table.Select; //选中全表
//设置表格的竖线
AMS_Table.Borders.item(wdBorderLeft).LineStyle := wdLineStyleSingle;
AMS_Table.Borders.item(wdBorderLeft).LineWidth := wdLineWidth050pt;
AMS_Table.Borders.item(wdBorderLeft).Color := wdColorAutomatic;
AMS_Table.Borders.Item(wdBorderRight).LineStyle := wdLineStyleSingle;
AMS_Table.Borders.item(wdBorderRight).LineWidth := wdLineWidth050pt;
AMS_Table.Borders.item(wdBorderRight).Color := wdColorAutomatic;
//设置表格顶上线
AMS_Table.Borders.Item(wdBorderTop).LineStyle := wdLineStyleSingle;
AMS_Table.Borders.item(wdBorderTop).LineWidth := wdLineWidth050pt;
AMS_Table.Borders.item(wdBorderTop).Color := wdColorAutomatic;
//设表格底线
AMS_Table.Borders.item(wdBorderBottom).LineStyle := wdLineStyleSingle;
AMS_Table.Borders.item(wdBorderBottom).LineWidth := wdLineWidth050pt;
AMS_Table.Borders.item(wdBorderBottom).Color := wdColorAutomatic;
//设中间横线
AMS_Table.Borders.item(wdBorderHorizontal).LineStyle := wdLineStyleSingle;
AMS_Table.Borders.item(wdBorderHorizontal).LineWidth := wdLineWidth050pt;
AMS_Table.Borders.item(wdBorderHorizontal).Color := wdColorAutomatic;
//设表两侧线
AMS_Table.Borders.item(wdBorderVertical).LineStyle := wdLineStyleSingle;
AMS_Table.Borders.item(wdBorderVertical).LineWidth := wdLineWidth050pt;
AMS_Table.Borders.item(wdBorderVertical).Color := wdColorAutomatic;
//正斜线反斜线
AMS_Table.Borders.item(wdBorderDiagonalDown).LineStyle := wdLineStyleNone;
AMS_Table.Borders.item(wdBorderDiagonalUp).LineStyle := wdLineStyleNone;
AMS_Table.Borders.Shadow := False;
end;
{**************************************************************************************
过程中文名称:光标定位到文件头部
功能说明:光标定位到文件头部
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.MoveToHome;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.HomeKey(Unit:=wdStory);
end;
{**************************************************************************************
过程中文名称:光标向上移一行
功能说明:光标向上移一行
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.MoveUp;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.MoveUP(Unit:=wdLine, Count:=1,Extend:=0);
FWordApp.Selection.HomeKey(Unit:=wdLine,Extend:=0);
end;
{**************************************************************************************
过程中文名称:光标定位到文件尾部
功能说明:光标定位到文件尾部
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.MoveToEnd;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.EndKey(Unit:=6);
end;
{**************************************************************************************
过程中文名称:光标向下移一行
功能说明:光标向下移一行
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.MoveDown;
begin
if VarType(FWordApp)<>varDispatch then exit;
FWordApp.Selection.MoveDown(Unit:=wdLine, Count:=1,Extend:=0);
FWordApp.Selection.HomeKey(Unit:=wdLine,Extend:=0);
end;
procedure TWordObject.RowNumber(NumberStyle:integer;StartNumber:integer=1);
begin
if VarType(FWordApp)<>varDispatch then exit;
// FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).NumberFormat:= '%1、' ;
// FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).TrailingCharacter:= $00000000;
// FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).NumberStyle := $00000027;
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).NumberPosition := NumberStyle*5;//;FWordApp.CentimetersToPoints(0);
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).Alignment := $00000000;
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).TextPosition := 0;//FWordApp.CentimetersToPoints(0.74);
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).TabPosition :=0;// FWordApp.CentimetersToPoints(1.27);
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).ResetOnHigher := 0;
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).StartAt := StartNumber;
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).ListLevels.Item(1).LinkedStyle :='' ;
FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle).Name:='';
FWordApp.Selection.Range.ListFormat.ApplyListTemplate(
ListTemplate:=FWordApp.ListGalleries.Item($00000002).ListTemplates.Item(NumberStyle),
ContinuePreviousList:=False,ApplyTo:=$00000000,
DefaultListBehavior:=$00000001);
end;
{**************************************************************************************
过程中文名称:选中全部并复制
功能说明:选中全部并复制
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.CopyAll;
begin
if VarType(FWordApp)<>varDispatch then exit;
if VarType(FCurrentDoc)<>varDispatch then exit;
FWordApp.Windows(FCurrentDoc.Name).Activate;
FWordApp.Selection.EndKey(Unit:=wdStory);
FWordApp.Selection.TypeParagraph;
FWordApp.Selection.Copy;
end;
{**************************************************************************************
过程中文名称:粘贴复制
功能说明:粘贴复制
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.PastAll;
begin
if VarType(FWordApp)<>varDispatch then exit;
if VarType(FCurrentDoc)<>varDispatch then exit;
FWordApp.Windows(FCurrentDoc.Name).Activate;
FWordApp.Selection.HomeKey(Unit:=wdStory);
FWordApp.Selection.EndKey(Unit:=wdStory, Extend:=wdExtend);
FWordApp.Selection.Paste;
end;
{**************************************************************************************
过程中文名称:打开某文件
功能说明:打开某文件
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
function TWordObject.OpenDoc(Const FullFileName: String): Boolean;
begin
Result:=False;
if VarType(FWordApp)<>varDispatch then exit;
if VarType(FCurrentDoc)=varDispatch then
try
FCurrentDoc.close;
FCurrentDoc:=FWordApp.Documents.open(FullFileName);
FWordApp.Windows(FCurrentDoc.Name).Activate;
result:=True;
except
Result:=False;
end;
end;
{
**************************************************************************************
过程中文名称:检查指定的文件名称的文档有没有初WORD打开.
功能说明:检查指定的文件名称的文档有没有初WORD打开.
参数说明: FullFileName: 指定的文件名称
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
class Function TWordObject.CheckDocOpen(Const FullFileName:String):Boolean;
var
i :integer;
Ms_Word :Variant; //打开的OLE对象
begin
Result:=False;
try
try
Ms_Word:=GetActiveOleObject('word.Application');
Except
Result:=False;
exit;
end;
For i:=1 to Ms_Word.Documents.Count do
begin
if Ms_Word.Documents.Item(i).FullName=FullFileName then
begin
Result:=true;
end;
end;
finally
Ms_Word:=Unassigned;
end;
end;
{**************************************************************************************
过程中文名称: 设置WORD视图显示的样式
功能说明: 设置WORD视图显示的样式
参数说明:
返回值:
最初编写日期:2004-6-10
最初编写人:李志文
*************************************************************************************** }
procedure TWordObject.Set_ViewStyle(const Value: TMs_WordView);
begin
if VarType(FWordApp)<>varDispatch then exit;
if FViewStyle <> Value then
begin
FViewStyle := Value;
case FViewStyle of
mwvNormail:
FWordApp.ActiveWindow.ActivePane.View.Type := wdNormalView;
mwvPageview:
FWordApp.ActiveWindow.ActivePane.View.Type := wdPrintView;
mwvMasterView:
FWordApp.ActiveWindow.ActivePane.View.Type :=wdMasterView;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -