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

  • 相关阅读:
    winform 关于Messagebox自动定时关闭
    Git常用命令
    使用消息队列异步化系统
    在Servlet(或者Filter,或者Listener)中使用spring的IOC容器
    基于Annotation与SpringAOP的缓存简单解决方案
    Ant自动构建
    Quartz定时调度
    Sybase数据库的分页功能
    oracle 日期相减
    n个List<Map>合并,Map中某属性值相等的value值相加
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1436892.html
Copyright © 2011-2022 走看看