怎么用delphi找查word文档中的指定字符串,找到后将字符串改变颜色
1个回答
2017-11-16 · 知道合伙人互联网行家
关注
展开全部
这个就是调用WORD函数的问题。
花了点时间给你作了一个演示。
uses
Word2000;
procedure TWMITaskManagerMainForm.ButtonWordClick(Sender: TObject);
var
WordApplication: TWordApplication;
WordDocument: TWordDocument;
DocInx, oFileName, CfCversions, oReadOnly, AddToRctFiles, PswDocument,
PswTemplate, oRevert, WPswDocument, WPswTemplate, oFormat, oEncoding, oVisible: OleVariant;
Idx: Integer;
Row: Integer;
Col: Integer;
_Cell: Cell;
begin
WordApplication := TWordApplication.Create(nil);
WordApplication.Visible := True;
WordDocument := TWordDocument.Create(nil);
DocInx := 1;
oFileName := 'c:\test.doc';
oReadOnly := True;
CfCversions := EmptyParam;
AddToRctFiles := EmptyParam;
PswDocument := EmptyParam;
PswTemplate := EmptyParam;
oRevert := EmptyParam;
WPswDocument := EmptyParam;
WPswTemplate := EmptyParam;
oFormat := EmptyParam;
oEncoding := EmptyParam;
oVisible := True;
WordApplication.Documents.Open(oFileName, CfCversions, oReadOnly, AddToRctFiles,
PswDocument, PswTemplate, oRevert, WPswDocument,
WPswTemplate, oFormat, oEncoding, oVisible);
WordDocument.ConnectTo(WordApplication.Documents.Item(DocInx));
Idx := 1;
//按列变换表格线不同颜色
{for Col := 1 to WordDocument.Tables.Item(Idx).Columns.Count do
begin
WordDocument.Tables.Item(Idx).Columns.Item(Col).Borders.OutsideColorIndex := Col;
end; }
//按行变换表格线不同颜色
{for Row := 1 to WordDocument.Tables.Item(Idx).Rows.Count do
begin
WordDocument.Tables.Item(Idx).Rows.Item(Row).Borders.OutsideColorIndex := Row;
end }
//下面是综合颜色变换 (按单元格)字体颜色、表格线颜色
{for Idx := 1 to WordDocument.Tables.Count do
begin
for Row := 1 to WordDocument.Tables.Item(Idx).Rows.Count do
begin
for Col := 1 to WordDocument.Tables.Item(Idx).Columns.Count do
begin
_Cell := WordDocument.Tables.Item(Idx).Cell(Row, col);
_Cell.Borders.OutsideColor := clBlue;
_Cell.Range.Font.Color := clRed;
end
end;
end;}
end;
花了点时间给你作了一个演示。
uses
Word2000;
procedure TWMITaskManagerMainForm.ButtonWordClick(Sender: TObject);
var
WordApplication: TWordApplication;
WordDocument: TWordDocument;
DocInx, oFileName, CfCversions, oReadOnly, AddToRctFiles, PswDocument,
PswTemplate, oRevert, WPswDocument, WPswTemplate, oFormat, oEncoding, oVisible: OleVariant;
Idx: Integer;
Row: Integer;
Col: Integer;
_Cell: Cell;
begin
WordApplication := TWordApplication.Create(nil);
WordApplication.Visible := True;
WordDocument := TWordDocument.Create(nil);
DocInx := 1;
oFileName := 'c:\test.doc';
oReadOnly := True;
CfCversions := EmptyParam;
AddToRctFiles := EmptyParam;
PswDocument := EmptyParam;
PswTemplate := EmptyParam;
oRevert := EmptyParam;
WPswDocument := EmptyParam;
WPswTemplate := EmptyParam;
oFormat := EmptyParam;
oEncoding := EmptyParam;
oVisible := True;
WordApplication.Documents.Open(oFileName, CfCversions, oReadOnly, AddToRctFiles,
PswDocument, PswTemplate, oRevert, WPswDocument,
WPswTemplate, oFormat, oEncoding, oVisible);
WordDocument.ConnectTo(WordApplication.Documents.Item(DocInx));
Idx := 1;
//按列变换表格线不同颜色
{for Col := 1 to WordDocument.Tables.Item(Idx).Columns.Count do
begin
WordDocument.Tables.Item(Idx).Columns.Item(Col).Borders.OutsideColorIndex := Col;
end; }
//按行变换表格线不同颜色
{for Row := 1 to WordDocument.Tables.Item(Idx).Rows.Count do
begin
WordDocument.Tables.Item(Idx).Rows.Item(Row).Borders.OutsideColorIndex := Row;
end }
//下面是综合颜色变换 (按单元格)字体颜色、表格线颜色
{for Idx := 1 to WordDocument.Tables.Count do
begin
for Row := 1 to WordDocument.Tables.Item(Idx).Rows.Count do
begin
for Col := 1 to WordDocument.Tables.Item(Idx).Columns.Count do
begin
_Cell := WordDocument.Tables.Item(Idx).Cell(Row, col);
_Cell.Borders.OutsideColor := clBlue;
_Cell.Range.Font.Color := clRed;
end
end;
end;}
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询