如何使用c#以编程方式从Word文档中删除一行?

nai*_*own 4 .net c# ms-word

我有一些代码来查找和替换word文档中的字段与数据集中的值.

Word.Document oWordDoc = new Word.Document();  
foreach (Word.Field mergeField in oWordDoc.Fields)  
{  
   mergeField.Select();  
   oWord.Selection.TypeText( stringValueFromDataSet );  
}
Run Code Online (Sandbox Code Playgroud)

在某些情况下stringValueFromDataSet是空的,除了什么都不插入,我想实际删除当前行.

知道我怎么能这样做吗?

nai*_*own 5

好吧,这最终是非常容易的.

oWord.Selection.TypeBackspace();//remove the field
oWord.Selection.TypeBackspace();//remove the line