Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Delphi将单词范围替换为内容控件_Delphi_Ms Word_Office365 - Fatal编程技术网

使用Delphi将单词范围替换为内容控件

使用Delphi将单词范围替换为内容控件,delphi,ms-word,office365,Delphi,Ms Word,Office365,是否可以使用Delphi在Word中以编程方式将范围定义为ContentControl 我们有许多模板,根据用户在Delphi应用程序中所做的选择插入了boiler plate文本。这些选择还可能导致删除书签范围 我们更新或删除书签范围的代码如下: var R: WordRange; bookmark: OleVariant; ... bookmark := 'bookmarkName'; R := MainFOrm.WordDoc.Bookmarks.Item(bookmark).Ra

是否可以使用Delphi在Word中以编程方式将范围定义为ContentControl

我们有许多模板,根据用户在Delphi应用程序中所做的选择插入了boiler plate文本。这些选择还可能导致删除书签范围

我们更新或删除书签范围的代码如下:

var
  R: WordRange;
  bookmark: OleVariant;
...
bookmark := 'bookmarkName';
R := MainFOrm.WordDoc.Bookmarks.Item(bookmark).Range;
if (addText = true) begin
  R.Text := 'This is the text to insert';
  R.HighlightColorIndex := wdTurquoise;
end else begin
  R.Delete(EmptyParam, EmptyParam);
end;
...
理想情况下,在上面的示例中,我们将范围定义为显示默认文本的富文本内容控件

这将与上面提到的其他书签一起出现


或者,我们可以在模板上定义富文本控件,并根据需要更新/删除它们?

以下内容将Word模板中的书签替换为富文本内容控件,显示所需的占位符文本

var
  bookmark: OleVariant;
  newCC: ContentControl;
  ccBlock: BuildingBlock;
  ccRange: WordRange;
  R: WordRange;
begin
  bookmark := 'bookmarkName';
  R := MainForm.WordDoc.Bookmarks.Item(bookmark).Range;
  // Clear any text in the template
  R.Text := '';
  // Create the new control
  newCC := MainForm.WordDoc.ContentControls.Add(wdContentControlRichText, R);
  // ccBlock and ccRange are optional but won't accept EmptyParam
  newCC.SetPlaceholderText(ccBlock, ccRange, Trim(Memo2.Text));
  // We can reuse ccRange to highlight the placeholder text. Defining earlier breaks setPlaceHolder
  ccRange := newCC.Range;
  ccRange.HighlightColorIndex := wdYellow;
end;