本文整理汇总了C#中Microsoft.Office.Interop.Word.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.GetEnumerator方法的具体用法?C# Microsoft.Office.Interop.Word.GetEnumerator怎么用?C# Microsoft.Office.Interop.Word.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Word
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Word.GetEnumerator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEnumerator
//public static string GetContentControlValueByTag(string location, string tag)
//{
// // Open the Word document specified by "location".
// using (WordprocessingDocument theDoc = WordprocessingDocument.Open(location, true))
// {
// // Get the package part that holds the main document content.
// MainDocumentPart mainPart = theDoc.MainDocumentPart;
// // Find the content content control whose Tag value == tag.
// // In this case, the tag value is "idPolicyNumber".
// SdtRun policyNumberCC = mainPart.Document.Body.Descendants<SdtRun>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == tag).SingleOrDefault();
// // Find the <sdtContent> element of the content control.
// SdtContentRun contentRun = policyNumberCC.GetFirstChild<SdtContentRun>();
// // Get the string inside the content control.
// string policyNumber = contentRun.GetFirstChild<Run>().GetFirstChild<Text>().InnerText;
// return policyNumber;
// }
//}
public IEnumerator<Word.ContentControls> GetEnumerator(Word.ContentControls contentControls)
{
System.Collections.IEnumerator en = contentControls.GetEnumerator();
var ob = new List<object>();
while (en.MoveNext())
{
// VSTO Document.Controls includes all managed controls, not just
// VSTO ContentControls; return only those.
if (en.Current is Microsoft.Office.Tools.Word.ContentControl)
{
// The control's name isn't stored with the control, only when it was added,
// so use a placeholder name for the wrapper.
ob.Add(en.Current);
//yield return new ContentControl("Unknown", (Microsoft.Office.Tools.Word.ContentControl)en.Current);
}
}
return ob as IEnumerator<Word.ContentControls>;
}