当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Word.Delete方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Word.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Word.Delete方法的具体用法?C# Microsoft.Office.Interop.Word.Delete怎么用?C# Microsoft.Office.Interop.Word.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Word的用法示例。


在下文中一共展示了Microsoft.Office.Interop.Word.Delete方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveTrailingBracket

 static void RemoveTrailingBracket(Wd.Range range)
 {
     range.MoveEnd(Wd.WdUnits.wdCharacter, 2);
     if (range.Characters.Count == 2 && range.Text == "\")")
         range.Delete();
     range.Collapse(Wd.WdCollapseDirection.wdCollapseStart);
 }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:7,代码来源:DeleteControlIf.cs

示例2: DeleteParagraphIfEmpty1

 static void DeleteParagraphIfEmpty1(Wd.ContentControl control)
 {
     Wd.Range range = control.Range;
     control.Delete(true);
     if (range.Paragraphs[1].IsEmpty())
         range.Paragraphs[1].Range.Delete();
 }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:7,代码来源:Optional.cs

示例3: RemovePreceedingComma

 static void RemovePreceedingComma(Wd.Range range)
 {
     range.MoveStart(Wd.WdUnits.wdCharacter, -2);
     if (range.Characters.Count == 2 && range.Text == ", ")
         range.Delete();
     range.Collapse(Wd.WdCollapseDirection.wdCollapseEnd);
 }
开发者ID:beachandbytes,项目名称:GorillaDocs,代码行数:7,代码来源:DeleteControlIf.cs

示例4: Delete1Hl

        /// <summary>
        /// Delete certain hyperlink
        /// </summary>
        /// <param name="h">the link itself</param>
        private void Delete1Hl(Word.Hyperlink h)
        {
            if (!LinkIsOurs(h)) return;
#if with_LinkCache
            if (LinkCache.ContainsKey(h)) LinkCache.Remove(h);
#endif//with_LinkCache
            //check if we have set this link: 1)by address(contains http://eur-lex...) and 2) has color wdRed or wdGreen: todo
            try
            {
                if (h != null) if (h.Range != null) if (h.Range.Font != null) h.Range.Font.ColorIndex = Word.WdColorIndex.wdBlack;
            }
            catch { }
            //System.Windows.Forms.MessageBox.Show(hl.Range.Text.ToString() + "\n" + hl.Address.ToString());
            h.Delete();
        }
开发者ID:apis-bulgaria,项目名称:EUCases.EULinksChecker,代码行数:19,代码来源:EULinksCheckerAddIn.cs

示例5: copyBuildingBlockLogic

        public void copyBuildingBlockLogic(Word.Document target, Word.Range range)
        {
            // FabDotxAsTemplate.OpenAsDocument() throws:
            //     This object model command is not available while in the current event.
            // Documents.Open(the dotx) is not allowed either
            // so make a temporary copy.

            //string tmp = System.IO.Path.GetTempFileName();
            //System.IO.File.Copy(templatePath, tmp, true);
            // .. but that fails the second time
            Word.Document fabdocx;
            try
            {
                //fabdocx = openDocument(tmp);
                fabdocx = FabDotxAsTemplate.OpenAsDocument();
            }
            catch (Exception e)
            {
                log.Error(e);
                throw e;
            }

            Model srcModel = Model.ModelFactory(fabdocx);

            Helpers.LibraryHelper libHelp = new Helpers.LibraryHelper(srcModel);
            try
            {
                libHelp.identifyLogic(range);
            }
            catch (Helpers.BuildingBlockLogicException bble)
            {
                log.Error(bble);
                MessageBox.Show("You can't reuse repeating content in a repeat"); // TODO, relax this restriction
                range.Delete();
                return;
            }

            Model targetModel = Model.ModelFactory(target);

            try
            {
                libHelp.injectLogic(targetModel, false, true, false);
                libHelp.updateBindings(range, targetModel.answersPart);
                // OK, remove od:source from the cc's
                // in our document
                libHelp.TagsSourceRemove(range);
            }
            catch (Helpers.BuildingBlockLogicException bble)
            {
                log.Error(bble);
                MessageBox.Show("ID collision"); // TODO, relax this restriction
                range.Delete();
                return;
            }
            finally
            {
                // OK to close the template now
                closeDocument(fabdocx);
                //System.IO.File.Delete(tmp);
                //log.Debug("deleted " + tmp);
            }
        }
开发者ID:plutext,项目名称:OpenDoPE-NoXML-WordAddIn,代码行数:62,代码来源:GlobalTemplateManager.cs

示例6: removeRangeTextAndRepositionCursor

        public void removeRangeTextAndRepositionCursor(Word.Range range)
        {
            range.Delete();

            // Reposition the cursor to the end of the sentence
            int position = extensionRange.End;
            Globals.ThisAddIn.Application.Selection.SetRange(position, position);
            highlight(extensionRange);
            scrollToRange(extensionRange);

            isRetrieving = 1;

            if (extensionPos == -1)
                resetExtensionMode();
        }
开发者ID:autocompaste,项目名称:AutoComPaste,代码行数:15,代码来源:ExtensionMode.cs

示例7: removeButKeepContents

 protected void removeButKeepContents(Word.ContentControl copiedCC)
 {
     log.Warn("Deleting cc " + copiedCC.Tag);
     copiedCC.Delete(); // keeps contents
 }
开发者ID:plutext,项目名称:OpenDoPE-NoXML-WordAddIn,代码行数:5,代码来源:ContentControlHandlerAbstract.cs

示例8: editXPath


//.........这里部分代码省略.........
                // the old one (if any)
                if (xppe == null)
                {
                    xppe = new XPathsPartEntry(model);
                }

                xppe.setup("rpt", cxpId, strXPath, prefixMappings, false);
                xppe.save();

                cc.Title = "Repeat: " + xppe.xpathId;
                // Write tag
                td.set("od:repeat", xppe.xpathId);
                cc.Tag = td.asQueryString();
            }
            else if (isBind)
            {
                // Create the new bind. Doesn't attempt to delete
                // the old one (if any)
                if (xppe == null)
                {
                    xppe = new XPathsPartEntry(model);
                }

                Word.XMLMapping bind = cc.XMLMapping;
                bool mappable = bind.SetMapping(strXPath, prefixMappings,
                    CustomXmlUtilities.getPartById(document, cxpId) );
                if (mappable) {
                    // What does the XPath point to?
                    string val = cc.XMLMapping.CustomXMLNode.Text;

                    cc.Title = "Data value: " + xppe.xpathId;

                    if (ContentDetection.IsBase64Encoded(val))
                    {
                        // Force picture content control ...
                        // cc.Type = Word.WdContentControlType.wdContentControlPicture;
                        // from wdContentControlText (or wdContentControlRichText for that matter)
                        // doesn't work (you get "inappropriate range for applying this
                        // content control type").

                        cc.Delete(true);

                        // Now add a new cc
                        object missing = System.Type.Missing;
                        Globals.ThisAddIn.Application.Selection.Collapse(ref missing);
                        cc = document.ContentControls.Add(
                            Word.WdContentControlType.wdContentControlPicture, ref missing);

                        cc.XMLMapping.SetMapping(strXPath, prefixMappings,
                            CustomXmlUtilities.getPartById(document, cxpId));

                    } else if (ContentDetection.IsXHTMLContent(val) )
                    {
                        td.set("od:ContentType", "application/xhtml+xml");
                        cc.Tag = td.asQueryString();

                        cc.XMLMapping.Delete();
                        cc.Type = Word.WdContentControlType.wdContentControlRichText;
                        cc.Title = "XHTML: " + xppe.xpathId;

                        if (Inline2Block.containsBlockLevelContent(val))
                        {
                            Inline2Block i2b = new Inline2Block();
                            cc = i2b.convertToBlockLevel(cc, true);

                            if (cc == null)
                            {
                                MessageBox.Show("Problems inserting block level XHTML at this location.");
                                return;
                            }

                        }
                    }

                    xppe.setup(null, cxpId, strXPath, prefixMappings, true);
                    xppe.save();

                    td.set("od:xpath", xppe.xpathId);

                    cc.Tag = td.asQueryString();

                } else
                {
                    xppe.setup(null, cxpId, strXPath, prefixMappings, true);
                    xppe.save();

                    td.set("od:xpath", xppe.xpathId);

                    cc.Title = "Data value: " + xppe.xpathId;
                    cc.Tag = td.asQueryString();

                    log.Warn(" XPath \n\r " + strXPath
                        + "\n\r does not return an element. The OpenDoPE pre-processor will attempt to evaluate it, but Word will never update the result. ");
                    bind.Delete();
                    MessageBox.Show(" XPath \n\r " + strXPath
                        + "\n\r does not return an element. Check this is what you want? ");
                }

            }
        }
开发者ID:plutext,项目名称:OpenDoPE-Mapping-WordAddIn,代码行数:101,代码来源:RibbonMapping.cs

示例9: convertToBlockLevel

        /// <summary>
        /// An inline rich text control can't contain carriage returns.
        /// </summary>
        /// <param name="control"></param>
        public Word.ContentControl convertToBlockLevel(Word.ContentControl currentCC, bool keepContents, bool updateScreen)
        {
            Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;
            OpenDoPEModel.DesignMode designMode = new OpenDoPEModel.DesignMode(document);

            // Only do it if the content control is rich text
            if (!currentCC.Type.Equals(Word.WdContentControlType.wdContentControlRichText))
            {
                log.Warn("convert to block level only operates on rich text controls, not " + currentCC.Type);
                return null;
            }

            string majorVersionString = Globals.ThisAddIn.Application.Version.Split(new char[] { '.' })[0];
            int majorVersion = Convert.ToInt32(majorVersionString);

            // Only do it if the content control is not already block level
            //
            if (isBlockLevel(currentCC)) return currentCC;

            // Can only do this if the content control is not
            // nested within some other inline content control
            if (currentCC.ParentContentControl != null
                && !isBlockLevel(currentCC.ParentContentControl))
            {
                MessageBox.Show("This content control contains block level content, but can't be converted automatically.  Please correct this yourself, by deleting it, and re-creating at block level.");
                return null;
            }

            if (majorVersion >= 14)
            {
                getWordApp().UndoRecord.StartCustomRecord("Promote content control to block-level");
            }

            bool ccIsAtPStart = ccStartsAtStartOfParagraph(currentCC);

            object collapseStart = Word.WdCollapseDirection.wdCollapseStart;
            //object collapseEnd = Word.WdCollapseDirection.wdCollapseEnd;
            object unitCharacter = Word.WdUnits.wdCharacter;

            // Get a range start of cc.
            Word.Range ccRange = currentCC.Range;
            ccRange.Collapse(ref collapseStart);

            // Delete the cc, but preserve Tag, Title
            string tagVal = currentCC.Tag;
            string titleVal = currentCC.Title;
            string contents = currentCC.Range.Text;

            currentCC.Delete(true);

            ccRange.Select();
            if (ccIsAtPStart)
            {
                document.Windows[1].Selection.TypeParagraph();
            }
            else
            {
                // Insert 2 new paragraphs
                document.Windows[1].Selection.TypeParagraph();
                document.Windows[1].Selection.TypeParagraph();
            }

            // Create a cc around the first new p
            object start = ccRange.Start+1;
            object end = ccRange.Start+1;
            object newRange = document.Range(ref start, ref end);
            log.Info("target {0}, {1}", ((Word.Range)newRange).Start, ((Word.Range)newRange).End);

            designMode.Off();
            Word.ContentControl newCC = document.ContentControls.Add(Word.WdContentControlType.wdContentControlRichText, ref newRange);
            designMode.restoreState();

            newCC.Tag = tagVal;
            newCC.Title = titleVal;
            if (keepContents) // want to do this for XHTML
            {
                newCC.Range.Text = contents;
            }

            if (updateScreen)
            {
                newCC.Application.ScreenUpdating = true;
                newCC.Application.ScreenRefresh();
            }
            return newCC;

            // Approach:
            //  .. Get the paragraph
            // .. Make a copy
            // .. in the copy, delete up to our position
            // .. in the original, delete after our position

            //Word.Range splittingPoint = sel.Range;

            //object para1DeleteStartPoint = splittingPoint.Start;

//.........这里部分代码省略.........
开发者ID:plutext,项目名称:OpenDoPE-Mapping-WordAddIn,代码行数:101,代码来源:Inline2Block.cs

示例10: ProcessWordField

        private static void ProcessWordField(Dictionary<string, string> dictionary, Word.Field field, Word.Application word)
        {
            if (field.Code == null) return;
            if (String.IsNullOrEmpty(field.Code.Text) == true) return;

            foreach (var key in dictionary.Keys)
            {
                string MergeFieldKey = string.Format(MERGEFIELD_PATTERN_0, key);
                if (field.Code.Text.IndexOf(MergeFieldKey) > -1)
                {
                    string value = dictionary[key];
                    if (String.IsNullOrEmpty(value) == true)
                    {
                        //field.Code.Text = String.Empty;
                        field.Delete();
                        break;
                    }

                    if (key.IndexOf(PICTURE) > -1)
                    {
                        InsertPicture(field, word, value);

                    }
                    else
                    {
                        InsertText(field, word, value);
                    }
                    break;
                }

            }
        }
开发者ID:Rukhlov,项目名称:DataStudio,代码行数:32,代码来源:DocumentServer.cs


注:本文中的Microsoft.Office.Interop.Word.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。