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

  • 相关阅读:
    ACM 01背包问题
    HDU 1222(数论,最大公约数)
    HDU 1045(质因数分解)
    HDU 4548(美素数)
    POJ 1458 Common Subsequence
    light oj 1047-neighbor house
    POJ 3903 Stock Exchange
    HDU 1069 monkey an banana DP LIS
    max sum
    ACM比赛
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1436892.html
Copyright © 2011-2022 走看看