Ejemplo n.º 1
0
        private void MoveText(CardControl TOPCARD, CardControl BOTTOMCARD)
        {
            //Globals.ThisAddIn.userControlWPF.ListCardControls.IndexOf(card)


            if (int.Parse(BOTTOMCARD.IDfield) != 1)// if it is not the first card
            {
                string nobookmark = "None";

                if ((TOPCARD.Bookmarkfield.ToUpper() != nobookmark.ToUpper()) && (BOTTOMCARD.Bookmarkfield.ToUpper() != nobookmark.ToUpper()))     // only if both are linked to a bookmark - to upper to maintain compatibility with old format
                {
                    Word.Bookmark TOPbmk   = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks[TOPCARD.Bookmarkfield];
                    Word.Range    TOPRange = TOPbmk.Range;

                    // move the text
                    Word.Bookmark BOTTOMbmk   = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks[BOTTOMCARD.Bookmarkfield];
                    Word.Range    BOTTOMRange = BOTTOMbmk.Range;
                    BOTTOMRange.Cut();

                    Word.Range temprange         = Globals.ThisAddIn.Application.ActiveDocument.Range(TOPRange.Start, TOPRange.End); // store range of prevbookmark
                    int        topbookmarkLenght = TOPRange.End - TOPRange.Start;                                                    // calculate lenght of prevbookmark subtracting end and start
                    string     topbkmName        = TOPbmk.Name;                                                                      // save name of prevbookmark
                    TOPbmk.Delete();                                                                                                 // delete prevbookmark
                    // add a temporary space character at the start of the previous bookmark
                    // paste the text
                    Word.Range newrange = Globals.ThisAddIn.Application.ActiveDocument.Range(temprange.Start, temprange.Start);
                    newrange.Paste();
                    Word.Range    newbkmrkrange = Globals.ThisAddIn.Application.ActiveDocument.Range(newrange.End, newrange.End + topbookmarkLenght);
                    Word.Bookmark newbookmark   = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks.Add(topbkmName, newbkmrkrange);  // create new bookmark with start at the end of the bookmark and end at start+lenght

                    //BOTTOMbmk.Range.Select();
                }
            }
        }
Ejemplo n.º 2
0
        private string ImportPdeTag(Word.Document wDoc, string key, string value)
        {
            if (wDoc == null || string.IsNullOrWhiteSpace(key) || string.IsNullOrWhiteSpace(value))
            {
                return(string.Empty);
            }

            // add a space before text.
            wDoc.Application.Selection.TypeText(" ");

            // add select text
            string bmValue = MarkupUtilities.GenTextXslTag(value, XsltType.Select, true);

            wDoc.Application.Selection.TypeText(bmValue);
            wDoc.Application.Selection.MoveLeft(Word.WdUnits.wdCharacter, bmValue.Length, Word.WdMovementType.wdExtend);

            // add select bookmark
            string bmName = Core.MarkupConstant.MarkupPdeTag + key;

            Word.Bookmark oldBm = null;
            foreach (Word.Bookmark bookmark in wDoc.Bookmarks)
            {
                if (string.Equals(bmName, bookmark.Name, StringComparison.OrdinalIgnoreCase))
                {
                    oldBm = bookmark;
                    break;
                }
            }
            if (oldBm != null)
            {
                oldBm.Delete();
            }
            Word.Range range = wDoc.Application.Selection.Range;
            wDoc.Bookmarks.Add(bmName, range);
            wDoc.Bookmarks.DefaultSorting = Word.WdBookmarkSortBy.wdSortByLocation;
            wDoc.Bookmarks.ShowHidden     = false;

            // set cursor after bookmark
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter, 1);

            // markup ProntoDoc;
            WKL.DataController.MainController.MainCtrl.CommonCtrl.CommonProfile.CurrentTemplateInfo.IsProntoDoc = true;
            if (!System.IO.File.Exists(wDoc.FullName))
            {
                wDoc.Application.Options.SaveInterval = 0;
            }

            return(bmName);
        }
Ejemplo n.º 3
0
        private string ImportPdeChart(Word.Document wDoc, string chartName, string chartContent)
        {
            string chartPath = AssetManager.FileAdapter.GenRandomFilePath(ChartExtension);
            string bmValue   = MarkupUtilities.GenTextXslTag(chartName, XsltType.Select, true);
            string bmName    = BaseMarkupUtilities.XmlEncode(chartName);

            // create temporary image
            bmName = string.Format("{0}{1}{2}", MarkupConstant.MarkupPdeTag, bmName, MarkupConstant.MarkupPdeChart);
            ProntoDoc.Framework.Utils.FileHelper.FileFromBase64(chartContent, chartPath);

            // delete old bm
            Word.Bookmark oldBm = null;
            foreach (Word.Bookmark bookmark in wDoc.Bookmarks)
            {
                if (string.Equals(bmName, bookmark.Name, StringComparison.OrdinalIgnoreCase))
                {
                    oldBm = bookmark;
                    break;
                }
            }
            if (oldBm != null)
            {
                oldBm.Delete();
            }

            // add image into word
            wDoc.Application.Selection.TypeText(" ");
            Word.InlineShape inlineShape = wDoc.Application.Selection.InlineShapes.AddPicture(chartPath, false, true);
            inlineShape.AlternativeText = MarkupUtilities.CreateAlternativeText(bmName, bmValue);

            // add bookmark
            wDoc.Application.Selection.MoveLeft(Word.WdUnits.wdCharacter, 1);
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter, 1, Word.WdMovementType.wdExtend);
            wDoc.Bookmarks.Add(bmName, wDoc.Application.Selection.Range);
            wDoc.Application.Selection.MoveRight(Word.WdUnits.wdCharacter);

            // delete temporary file
            System.IO.File.Delete(chartPath);

            return(bmName);
        }
Ejemplo n.º 4
0
        public void CloneBookmarkContent(string name, string newName = "")
        {
            if (!_document.Bookmarks.Exists(name))
            {
                return;
            }

            _document.Bookmarks[name].Range.Copy();
            _document.Bookmarks[name].Range.Select();
            _document.Application.Selection.Collapse(WordOM.WdCollapseDirection.wdCollapseEnd);

            WordOM.Bookmark bs = _document.Application.Selection.Bookmarks.Add(newName + "start");
            bs.Range.InsertAfter(" ");
            _document.Application.Selection.Move(WordOM.WdUnits.wdCharacter, 1);
            WordOM.Bookmark be = _document.Application.Selection.Bookmarks.Add(newName + "end");
            _document.Range(bs.Start, bs.End).Paste();

            WordOM.Range contentRange = _document.Range(bs.Start, be.End);
            contentRange.Bookmarks.Add(newName);

            bs.Delete();
            be.Delete();
        }
Ejemplo n.º 5
0
        public void Start()
        {
            try {
                //Make hidden document active to receive selection
                HiddenDoc.Activate();                 //results in a slight application focus loss
            }
            catch (System.Runtime.InteropServices.COMException ex) {
                if (ex.Message == "Object has been deleted.")
                {
                    //Open Blank document, then attach styles *and update
                    HiddenDoc = Globals.ThisAddIn.Application.Documents.Add(ref missing, ref missing, ref missing, ref FalseObj);
                    HiddenDoc.set_AttachedTemplate(ref templateObj);
                    HiddenDoc.UpdateStyles();
                    HiddenDoc.Activate();
                }
                else
                {
                    throw;
                }
            }

            //Remove Continue Bookmark, if exists
            Word.Bookmarks hiddenDocBookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
            if (hiddenDocBookmarks.Exists("Continue"))
            {
                object        deleteMarkObj = "Continue";
                Word.Bookmark deleteMark    = hiddenDocBookmarks.get_Item(ref deleteMarkObj);
                deleteMark.Select();
                deleteMark.Delete();
            }

            //Tell hidden document it has been saved to remove rare prompt to save document
            HiddenDoc.Saved = true;

            //Keep track when started
            started = true;
        }
Ejemplo n.º 6
0
        public void End()
        {
            //Exit quietly if buffer hasn't started
            if (!started)
            {
                return;
            }

            //Turn off buffer started flag
            started = false;

            //Verify hidden document is active
            if ((HiddenDoc as Word.Document) != Globals.ThisAddIn.Application.ActiveDocument)
            {
                HiddenDoc.Activate();
            }

            //Remove Continue Bookmark, if exists
            Word.Bookmarks hiddenDocBookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
            hiddenDocBookmarks.ShowHidden = true;
            if (hiddenDocBookmarks.Exists("Continue"))
            {
                object        deleteMarkObj = "Continue";
                Word.Bookmark deleteMark    = hiddenDocBookmarks.get_Item(ref deleteMarkObj);
                deleteMark.Delete();
            }

            //Hidden doc selection
            curSel = Globals.ThisAddIn.Application.Selection;

            //Hidden doc range
            Word.Range hiddenDocRange;
            Word.Range bufDocRange;

            //Select entire doc, save range
            curSel.WholeStory();
            bufDocRange = curSel.Range;

            //If cursor bookmark placed in, move there, else find end of text, put a bookmark there
            Boolean cursorFound = false;

            if (hiddenDocBookmarks.Exists("_cursor"))
            {
                object        cursorBookmarkObj = "_cursor";
                Word.Bookmark cursorBookmark    = hiddenDocBookmarks.get_Item(ref cursorBookmarkObj);
                bufDocRange.SetRange(cursorBookmark.Range.End, cursorBookmark.Range.End);
                cursorBookmark.Delete();
                cursorFound = true;
            }
            else
            {
                //The -2 is done because [range object].WordOpenXML likes to drop bookmarks at the end of the range
                bufDocRange.SetRange(curSel.End - 2, curSel.End - 2);
            }

            object bookmarkObj = bufDocRange;

            //Generate GUID for hidden bookmark
            System.Guid guid = System.Guid.NewGuid();
            String      id   = "_buf" + guid.ToString().Replace("-", string.Empty);

            Word.Bookmark mark = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks.Add(id, ref bookmarkObj);

            //Get OpenXML Text (Text with formatting)
            curSel.WholeStory();
            hiddenDocRange = curSel.Range;
            string XMLText = hiddenDocRange.WordOpenXML;

            //Clear out contents of buffer
            hiddenDocRange.Delete(ref missing, ref missing);             //comment this for docbuffer troubleshooting

            //Tell hidden document it has been saved to remove rare prompt to save document
            HiddenDoc.Saved = true;

            //Make primary document active
            Globals.ThisAddIn.Application.ActiveDocument.Activate();

            //Get selection from new active document
            curSel = Globals.ThisAddIn.Application.Selection;

            //insert buffered formatted text into main document
            curSel.InsertXML(XMLText, ref missing);

            //Place cursor at bookmark+1 (this is done due to WordOpenXML ignoring bookmarks at the end of the selection)
            Word.Bookmarks bookmarks = Globals.ThisAddIn.Application.ActiveDocument.Bookmarks;
            bookmarks.ShowHidden = true;

            object stringObj = id;

            Word.Bookmark get_mark = bookmarks.get_Item(ref stringObj);
            bufDocRange = get_mark.Range;

            if (cursorFound)             //Canned language actively placed cursor
            {
                bufDocRange.SetRange(get_mark.Range.End, get_mark.Range.End);
            }
            else             //default cursor at the end of text
            {
                bufDocRange.SetRange(get_mark.Range.End + 1, get_mark.Range.End + 1);
            }
            bufDocRange.Select();
        }