[英][VSTO Word]How to get the range after PasteAndFormat?
我的代码如下:
Word.Selection selection = wordApp.Selection;
Word.Range range = selection.Range;
MessageBox.Show("Range :" + range.Text);
range.Copy();
range.PasteAndFormat(Word.WdRecoveryType.wdFormatPlainText);
if (range == null)
MessageBox.Show("The Range is null currently");
else
MessageBox.Show("Range :" + range.Text);
比如新建一个Word文档,输入“ABC”,如果我select整个“ABC”运行程序,范围不会改变,但是如果我select单个字符运行程序,范围会变是null,为什么会这样? 我必须进一步编辑范围。
我更改了代码,现在我可以在 PasteAndFormat 之后获取范围。
Word.Selection selection = wordApp.Selection;
int start = selection.Start;
int count = selection.Text.Length;
selection.Copy();
selection.PasteAndFormat(Word.WdRecoveryType.wdFormatPlainText);
int newStart = selection.Start;
selection.SetRange(start, newStart);
Word.Range range = selection.Range;
if (range == null)
MessageBox.Show("The Range is null currently");
else
MessageBox.Show("Range :" + range.Text);
我想也许“范围”是一种格式,在 PasteAndFormat(wdFormatPlainText) 之后就会清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.