zoukankan      html  css  js  c++  java
  • c# word 在当前光标位置插入内容

    /// <summary>
            /// 在当前光标位置插入内容
            /// </summary>
            /// <param name="text">内容</param>
            public void SelectionInsertText(string text)
            {
                Word.Selection currentSelection = Application.Selection;

                // Store the user's current Overtype selection
                bool userOvertype = Application.Options.Overtype;

                // Make sure Overtype is turned off.
                if (Application.Options.Overtype)
                {
                    Application.Options.Overtype = false;
                }

                // Test to see if selection is an insertion point.
                if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP)
                {
                    //currentSelection.TypeText("Inserting at insertion point. ");
                    currentSelection.TypeText(text);
                    currentSelection.TypeParagraph();
                }
                else
                {
                    if (currentSelection.Type == Word.WdSelectionType.wdSelectionNormal)
                    {
                        // Move to start of selection.
                        if (Application.Options.ReplaceSelection)
                        {
                            object direction = Word.WdCollapseDirection.wdCollapseStart;
                            currentSelection.Collapse(ref direction);
                        }
                        //currentSelection.TypeText("Inserting before a text block. ");
                        currentSelection.TypeText(text);
                        currentSelection.TypeParagraph();
                    }
                    else
                    {
                        // Do nothing.
                    }
                }

                // Restore the user's Overtype selection
                Application.Options.Overtype = userOvertype;
            }

  • 相关阅读:
    php mysql与mysqli 区别
    让IT工作者过度劳累的12个坏习惯
    HR不懂爱,他的问题答不上来
    励志小故事
    php中如何把一个数字字符串作为一个变量
    新手应该具备的基本素质
    邮件中的缩写
    强大的网页性能测试工具Speed Tracer
    Windows环境下EditPlus运行Perl程序
    ActionScript3检测当前下载资源的速度
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1436892.html
Copyright © 2011-2022 走看看