Esempio n. 1
0
        //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>;
        }