删除带连字符的单词时,Range.Delete方法会插入空格 [英] Range.Delete method when deleting hyphenated words inserts blanks

查看:199
本文介绍了删除带连字符的单词时,Range.Delete方法会插入空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图通过我的VSTO AddIn(Win7 / Office 10 / VS 10)删除句子中的单词。

I'm attempting to delete words in a sentence via my VSTO AddIn (Win7/Office 10/VS 10).

这句话是:  "我们每天都在项目上工作。"

the sentence is:  "We work day-by-day on the project."

我想删除"每天"。

代码指令是:

Globals.ThisAddIn.Application.ActiveWindow.Selection.Sentences [0] .Words [3] .Delete(Word.WdUnits.wdWord,5);

Globals.ThisAddIn.Application.ActiveWindow.Selection.Sentences[0].Words[3].Delete(Word.WdUnits.wdWord, 5);

然而,结果是"删除"。方法结果为:

However, the results are that the "Delete" method results in:

day-(已删除)

< space> (已插入)

<space> (inserted)

by-(已删除)

结果是:  "我们工作 该项目的一天。"在"单词"之间有两个空格。和"天"。

resulting sentence is:  "We work  day on the project." with two spaces between "word" and "day".

怎么来的? 为什么插入空白? 为什么不删除最后一个单词"day"。 计数已关闭。

How come??  Why the insert of a blank?  Why not delete the last word "day".  The count is off.

任何变通办法建议??

Any workaround suggestions??

谢谢,billwa992

Thanks, billwa992

推荐答案

比尔,

我不知道代码如何工作(至少删除单词)。对我来说,您的代码抛出异常,因为Office对象的所有枚举都是基于1而不是基于0。所以在将代码更改为:

I don't know how the code works (delete words at least) on your side. For me, your code throw an exception as all enumerations of Office object is 1-based rather than 0-based. So after changing the code to:

 


Globals.ThisAddIn.Application.ActiveWindow.Selection.Sentences[1].Words[3].Delete(Word.WdUnits.wdWord, 5);


这篇关于删除带连字符的单词时,Range.Delete方法会插入空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆