【VSTO开发】range.Characters.First.Delete空格BUG

最近用到了:range.Characters.First.Delete函数,发现一个BUG,在此记录:

代码解释如下:

    /// Deletes the specified number of characters or words.
    /// Optional Object. The unit by which the collapsed range or selection is to be deleted. Can be one of the following  constants: wdCharacter (default) or wdWord.
    /// Optional Object. The number of units to be deleted. To delete units after the range or selection, collapse the range or selection and use a positive number. To delete units before the range or selection, collapse the range or selection and use a negative number.
    [DispId(127)]
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
    int Delete([MarshalAs(UnmanagedType.Struct), In, Optional] ref object Unit, [MarshalAs(UnmanagedType.Struct), In, Optional] ref object Count);

从代码说明可以看出    

range.Characters.First.Delete(WdUnits.wdCharacter,2)和range.Characters.First.Delete(2)应该是相同结果,但是实际执行时候发现,range.Characters.First.Delete(WdUnits.wdCharacter,2)中加入WdUnits.wdCharacter是有BUG的,特别是待删除文本中包含一个空格的时候,会不识别为字符。

我的测试word是2021。

在此记录一下,供大家点评!

你可能感兴趣的:(word,vsto,office,c#,开发语言,程序人生)