使用c#删除内容控件并保留填写的文本 [英] Removing Content Controls with c# and leaving filled in text
本文介绍了使用c#删除内容控件并保留填写的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Interop Word生成了word文档。现在我无法从生成的word文档中删除控件。
请在下面找到我的代码。
I have generated the word document using Interop Word.Now I'm unable to remove the controls from the generated word document.
Please find my code below.
Word.Application myWordApp = new Word.Application();
object missing = System.Reflection.Missing.Value;
object oTemplate = strWordDoc;
Word.Document document = myWordApp.Documents.Add(ref oTemplate, ref missing, ref missing, ref missing);
foreach (Word.ContentControl contentControl in document.ContentControls)
{
contentControl.SetPlaceholderText(null, null,"Trial");
}
myWordApp.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintView;
myWordApp.Visible = true;
object index = 1;
document.Windows.get_Item(ref index).View.Type = Word.WdViewType.wdPrintView;
推荐答案
大家都解决了我的问题:) :)感谢您的支持..
只需更换下面的代码
Hi all resolved my issue :):) thanks for the support..
Just replaced the code as below
foreach (Word.ContentControl contentControl in document.ContentControls)
{
contentControl.Range.Text="Trial";
contentControl.Delete(false);
}
这篇关于使用c#删除内容控件并保留填写的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文