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;
            }

  • 相关阅读:
    剑指offer系列——56.删除链表中重复的结点
    剑指offer系列——55.链表中环的入口结点
    剑指offer系列——54.字符流中第一个不重复的字符
    剑指offer系列——53.表示数值的字符串
    MinGW与Cygwin
    Android-x86虚拟机安装配置全攻略
    linux下使用NFS挂载文件系统
    ubuntu 64bit “arm-linux-gcc: No such file or directory”问题的解决方法
    虚拟机下ubuntu的minicom使用指南
    Linux 下编译、安装、配置 QT
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1436892.html
Copyright © 2011-2022 走看看