回复 6楼DCAgile的帖子
通过Bookmark定位,替换目标文本为 TextField 测试代码如下:
- private void Form1_Load(object sender, EventArgs e)
- {
- TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings();
- ls.ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord;
- ls.ApplicationFieldTypeNames = new string[] { "MERGEFIELD" };
- this.textControl1.Load(FilePath, StreamType.MSWord, ls);
- DTC = this.textControl1.DocumentTargets;
- this.textControl1.DocumentLinkClicked += textControl1_DocumentLinkClicked;
- List<int> bookmarks = new List<int>();
- foreach (DocumentTarget item in DTC)
- {
- bookmarks.Add(item.Start);
- }
- this.textControl1.Select(bookmarks[0]-1, bookmarks[1]-bookmarks[0]);
- TextField tf = new TextField();
- tf.Text = this.textControl1.Selection.Text;
- this.textControl1.Selection.Text="";
- this.textControl1.Select(bookmarks[0],0);
- this.textControl1.TextFields.Add(tf);
- this.textControl1.TextFieldClicked += textControl1_TextFieldClicked;
- }
复制代码 |