none
When using VSTO to create a word document, change font style in current selection caused the change of the style for the whole document. RRS feed

  • Question

  • OK, so after I created a table in word, the next step is to add footnote for that table.  The requirement is, superscript the number and then a line of text.  e.g. 1 resemble the meaning.  1 needs to be super scripted.

    object lastPosition = dRange.StoryLength - 1;

    dRange = dDocument.Range(ref lastPosition, ref lastPosition);      //move cursor to last

    dRange.Text = 1;

    dRange.Select();

    dRange.HighlightColorIndex = WdColorIndex.wdBrightGreen;   //I can see the green covers only the number 1

    Style oStyle = dRange.Application.Selection.get_Style();

    oStyle.Font.Size = 6.0f; //after this statement, all the items in previous table will be font 6.

    oStyle.Font.Superscript = 1; //now all the items in table will become super script.

    ...

    I have been struggle on this problem for a week.  I just couldn't find a way around this problem.  I have also add section break before I insert the footnote.  It was not stopping back change the font in table.

    Monday, October 24, 2016 9:38 PM

All replies

  • Hi,

    Based on your description, I will move your problem to VSTO forum:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=vsto

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.


    Regards,
    Emi Zhang
    TechNet Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, October 25, 2016 8:17 AM
  • Hi,

    From your code, you are actually adding a text and then make it superscript.

    If you want to add the footnote, you could try the code below:

     Range rng = Globals.ThisAddIn.Application.Selection.Range;
                Table tb= Globals.ThisAddIn.Application.ActiveDocument.Tables.Add(rng, 2, 2);
                object styleName = "Table Professional";
                tb.set_Style(ref styleName);
                object lastPosition = Globals.ThisAddIn.Application.Selection.Range.StoryLength - 1;
                Range dRange = Globals.ThisAddIn.Application.ActiveDocument.Range(ref lastPosition, ref lastPosition);      //move cursor to last
                //dRange.Text = "1";
                dRange.Select();
                dRange.HighlightColorIndex = WdColorIndex.wdBrightGreen;
                //I can see the green covers only the number 1
                Globals.ThisAddIn.Application.Selection.FootnoteOptions.Location = WdFootnoteLocation.wdBottomOfPage;
                Globals.ThisAddIn.Application.Selection.FootnoteOptions.NumberingRule = WdNumberingRule.wdRestartContinuous;
                Globals.ThisAddIn.Application.Selection.FootnoteOptions.StartingNumber = 1;
                Globals.ThisAddIn.Application.Selection.FootnoteOptions.NumberStyle = WdNoteNumberStyle.wdNoteNumberStyleArabic;
                Globals.ThisAddIn.Application.Selection.FootnoteOptions.LayoutColumns = 0;
                Globals.ThisAddIn.Application.Selection.Footnotes.Add(dRange);
    

    The result:


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, October 26, 2016 2:50 AM
    Moderator
  • Thanks for the reply.  There is a bit of problem with the style of the built-in footnote which does not meet the our document standard.  So, it seems I cannot utilize the that feature.

    I still need to figure out how to superscript a number.  Also I will need to figure out how to change the paragraph style without affecting previous paragraph.

    Regards,

    Wednesday, October 26, 2016 2:55 PM
  • Hi,

    In that situation, you could directly change the Superscript of the font like:

                Range dRange = Globals.ThisAddIn.Application.ActiveDocument.Range(ref lastPosition, ref lastPosition);      //move cursor to last
                dRange.Text = "1";
                dRange.Select();
                dRange.HighlightColorIndex = WdColorIndex.wdBrightGreen;
                Globals.ThisAddIn.Application.Selection.Font.Superscript = 1;

    Regards,

    Celeste




    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Saturday, October 29, 2016 9:02 AM
    Moderator