Exemple #1
0
        public void PopulateControl(string tag, string value)
        {
            WordOM.ContentControls contentControls = _document.SelectContentControlsByTag(tag);
            if (contentControls == null)
            {
                return;
            }
            foreach (WordOM.ContentControl contentControl in contentControls)
            {
                if (contentControl.Type == WordOM.WdContentControlType.wdContentControlCheckBox)
                {
                    if (!String.IsNullOrEmpty(value))
                    {
                        contentControl.Checked = Boolean.Parse(value);
                    }
                }
                else
                {
                    if (value != null && !String.IsNullOrEmpty(value))
                    {
                        value = value.Replace("\r\n", ((char)11).ToString(CultureInfo.InvariantCulture));
                    }

                    contentControl.Range.Text = value;
                }

                if (value != null)
                {
                    contentControl.SetPlaceholderText(null, null, value);
                }
            }
        }
        public void InitializeContentControlListView()
        {
            Color unmappedColor = ColorTranslator.FromHtml(Settings.Default.UnmappedCCForeColor);
            Color mappedColor   = ColorTranslator.FromHtml(Settings.Default.MappedCCForeColor);

            ccListView.Items.Clear();
            interopWord.ContentControls ccList = Globals.ThisAddIn.currentDocument.ContentControls;

            foreach (interopWord.ContentControl cc in ccList)
            {
                ListViewItem ccListViewItem = new ListViewItem(cc.Title);
                ccListViewItem.Tag = cc;
                if (!cc.XMLMapping.IsMapped)
                {
                    ccListViewItem.ForeColor = unmappedColor;
                }
                else
                {
                    ccListViewItem.ForeColor = mappedColor;
                }
                ccListViewItem.SubItems.Add(cc.XMLMapping.XPath);
                if (cc.XMLMapping.IsMapped)
                {
                    ccListViewItem.SubItems.Add(cc.XMLMapping.CustomXMLNode.Text);
                }
                else
                {
                    ccListViewItem.SubItems.Add(cc.Range.Text);
                }

                ccListView.Items.Add(ccListViewItem);
            }
        }
Exemple #3
0
        public void btnSyncField_Click(IRibbonControl control)
        {
            var doc             = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);
            int proptectionType = -1;

            try
            {
                proptectionType = doc.TurnOffProtection(String.Empty);
                WordOM.ContentControl contentcontrol = Globals.ThisAddIn.Application.Selection.Range.ParentContentControl;
                if (contentcontrol == null)
                {
                    return;
                }
                WordOM.ContentControls matchingControls =
                    Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTag(contentcontrol.Tag);
                foreach (WordOM.ContentControl mc in matchingControls)
                {
                    mc.Range.Text = contentcontrol.Range.Text;
                }
            }
            catch (Exception e)
            {
                var logger = new EventViewerLogger();
                logger.Log(e.ToString(), Type.Error);

#if DEBUG
                MessageBox.Show(e.ToString(), @"sorry");
#endif
            }
            finally
            {
                doc.TurnOnProtection(proptectionType, String.Empty);
            }
        }
Exemple #4
0
        public void btnLock_Click(IRibbonControl control)
        {
            foreach (WordOM.Table table in Globals.ThisAddIn.Application.ActiveDocument.Tables)
            {
                try
                {
                    WordOM.ContentControls controls = table.Range.ContentControls;
                    if (controls == null || controls.Count == 0)
                    {
                        continue;
                    }

                    table.Select();
                    Globals.ThisAddIn.Application.Selection.Range.ContentControls.Add(WordOM.WdContentControlType.wdContentControlGroup);
                }
                catch (Exception e)
                {
#if DEBUG
                    MessageBox.Show(e.ToString(), @"sorry");
#endif
                }
            }


            string storedMode = Globals.ThisAddIn.Application.ActiveDocument.GetPropertyValue(Constants.WordDocumentProperties.ToggleLockMode);
            string newMode    = String.Equals(storedMode, Constants.WordDocumentPropertyValues.ToggleLockModeUnlocked) ? Constants.WordDocumentPropertyValues.ToggleLockModeLocked : Constants.WordDocumentPropertyValues.ToggleLockModeUnlocked;
            Globals.ThisAddIn.Application.ActiveDocument.UpdateOrCreatePropertyValue(Constants.WordDocumentProperties.ToggleLockMode, newMode);
            ribbon.Invalidate();
        }
        // returns a list of all of the strings that exist in text boxes in the current document
        private List <string> getPlainText()
        {
            List <string> textList = new List <string>(); //here is where we store all of the responses from the form

            foreach (Word.Range sentence in doc.Sentences)
            {
                if (sentence.ShapeRange.Count > 0) //if there are shapes
                {
                    foreach (Word.Shape shape in sentence.ShapeRange)
                    {
                        if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoTextBox)                         //if it's a textbox
                        {
                            Word.ContentControls allContentControls = shape.TextFrame.TextRange.ContentControls; //get the collection of Content Controls in the shape

                            /*
                             * If there are check boxes, figure out which ones are checked and add that to the list
                             */
                            if (allContentControls.Count > 0)               //if there are content controls
                            {
                                List <int> checkedBoxes = new List <int>(); //a list to store the numbers of the content controls that are checked
                                int        num          = 1;                //to track which content control we're on
                                string     finalString  = "Rating: ";       //this is what will be added to the text list

                                foreach (Word.ContentControl cc in allContentControls)
                                {
                                    if (cc.Checked == true)
                                    {
                                        checkedBoxes.Add(num);
                                        num++;
                                    }
                                    else
                                    {
                                        num++;
                                    }
                                }

                                foreach (int i in checkedBoxes)
                                {
                                    Trace.WriteLine(i + " is checked");
                                    finalString = finalString + i + " ";
                                }

                                textList.Insert(0, finalString + "\n");
                            }

                            //otherwise, just add the text in the textbox to the list
                            else
                            {
                                textList.Insert(0, shape.TextFrame.TextRange.Text + "\n"); // prepend each object to the list so that the document will print top to bottom
                            }
                        }
                    }
                }
            }

            return(textList);
        }
Exemple #6
0
 public void RenameControl(string tag, string newTag)
 {
     WordOM.ContentControls contentControls = _document.SelectContentControlsByTag(tag);
     if (contentControls == null)
     {
         return;
     }
     foreach (WordOM.ContentControl contentControl in contentControls)
     {
         contentControl.Tag = newTag;
     }
 }
Exemple #7
0
 public void DeleteControl(string tag)
 {
     WordOM.ContentControls contentControls = _document.SelectContentControlsByTag(tag);
     if (contentControls == null)
     {
         return;
     }
     foreach (WordOM.ContentControl contentControl in contentControls)
     {
         contentControl.Delete(true);
     }
 }
Exemple #8
0
        public void SyncTable()
        {
            // var doc = new OfficeDocument(Globals.ThisAddIn.Application.ActiveDocument);
            //var proptectionType = -1;
            try
            {
                //proptectionType = doc.TurnOffProtection(String.Empty);


                WordOM.Tables tables = Globals.ThisAddIn.Application.Selection.Tables;
                if (tables == null || tables.Count == 0)
                {
                    MessageBox.Show(@"Please ensure your cursor is within a table", @"No Table Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                WordOM.Table table = tables[1];


                WordOM.ContentControls contentcontrols = table.Range.ContentControls;
                if (contentcontrols == null)
                {
                    return;
                }

                foreach (WordOM.ContentControl contentControl in contentcontrols)
                {
                    if (String.IsNullOrEmpty(contentControl.Tag))
                    {
                        continue;
                    }

                    WordOM.ContentControls matchingControls =
                        Globals.ThisAddIn.Application.ActiveDocument.SelectContentControlsByTag(contentControl.Tag);
                    foreach (WordOM.ContentControl mc in matchingControls)
                    {
                        mc.Range.Text = contentControl.Range.Text;
                    }
                }
            }
            catch (Exception e)
            {
                var logger = new EventViewerLogger();
                logger.Log(e.ToString(), Type.Error);

#if DEBUG
                MessageBox.Show(e.ToString(), @"sorry");
#endif
            }
        }
Exemple #9
0
        public void RenameControlInBookmark(string tag, string newTag, string bookmarkName)
        {
            if (!_document.Bookmarks.Exists(bookmarkName))
            {
                return;
            }

            WordOM.ContentControls contentControls = _document.Bookmarks[bookmarkName].Range.ContentControls;
            if (contentControls == null)
            {
                return;
            }
            foreach (WordOM.ContentControl contentControl in contentControls)
            {
                contentControl.Tag = newTag;
            }
        }
Exemple #10
0
        public void PopulateControlInBookmark(string bookmarkName, string tag, string value)
        {
            if (!_document.Bookmarks.Exists(bookmarkName))
            {
                return;
            }

            WordOM.ContentControls contentControls = _document.Bookmarks[bookmarkName].Range.ContentControls;
            if (contentControls == null)
            {
                return;
            }
            foreach (WordOM.ContentControl contentControl in contentControls)
            {
                contentControl.Range.Text = value;
            }
        }
Exemple #11
0
        public string ReadContentControlValue(string tag)
        {
            WordOM.ContentControls contentControls = _document.SelectContentControlsByTag(tag);
            if (contentControls.Count < 1)
            {
                return(string.Empty);
            }


            switch (contentControls[1].Type)
            {
            case WordOM.WdContentControlType.wdContentControlCheckBox:
                return((contentControls.Count < 1) ? String.Empty : contentControls[1].Checked.ToString());

            default:
                return((contentControls.Count < 1) ? String.Empty : contentControls[1].Range.Text);
            }
        }