none
Question about updating Table of Authority RRS feed

  • Question

  • Hi,

    I am currently working on inserting Table of Authorities. After I insert table of authorities, I try to apply font size and other formatting properties. Once I apply, due to changes page number it points to are no longer correct. If I try to do TableOfAuthority update then I lose all the formatting.

    Is there anyway I could preserve the formatting and also have correct page numbers once update of TableofAuthorities is called ?

    Thanks,

    Arun

    Wednesday, February 4, 2015 5:38 PM

All replies

  • Hi Arun,

    How do you change the format? For Table of Authority, we need to change corresponding style instead of change the format in the Font tab directly.

    For example, to change the header of TOA:

    With ActiveDocument.Styles("TOA Heading").Font
    XXXX
    End With

    # Styles Object (Word)

    https://msdn.microsoft.com/en-us/library/office/ff837469(v=office.15).aspx

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, February 5, 2015 6:58 AM
    Moderator
  • Can you share code snippet corresponding to C# ?

    I tried something like this.

    foreach (TableOfAuthorities tab in application.ActiveDocument.TablesOfAuthorities)
          {
                    object tableStyle = WdStyleType.wdStyleTypeTable;
                    Style newStyle = application.ActiveDocument.Styles.Add("Table of Authorities", ref tableStyle);
                    newStyle.Font.Size = 12;
                    newStyle.Font.Name = "Arial";
                    tab.Update();
          }

    I want to ensure that the table of authorities maintain correct formatting and page number after I call Update method.

    Thursday, February 5, 2015 6:35 PM
  • Hi Nitrup,

    The style of Table of Authorities and TOA Heading are built-in styles. So, we need to change the format for these styles.

    Word.Style TAOStyle = Application.ActiveDocument.Styles["Table of Authorities"];
                TAOStyle.Font.Size = 12;
                TAOStyle.Font.Name = "Arial";
                Word.Style TAOHeaderStyle = Application.ActiveDocument.Styles["TOA Heading"];
                TAOHeaderStyle.Font.Size = 16;
                TAOHeaderStyle.Font.Name = "Arial";
                TAOHeaderStyle.Font.Bold = 1;
                foreach (Word.TableOfAuthorities tab in Application.ActiveDocument.TablesOfAuthorities)
                {
                    object tableStyle = Word.WdStyleType.wdStyleTypeTable;
                    //Word.Style newStyle = Application.ActiveDocument.Styles.Add("Table of Authorities", ref tableStyle);
                    
                    //newStyle.Font.Size = 12;
                    //newStyle.Font.Name = "Arial";
                    
                    tab.Update();
                }

    Regards

    Starain

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 6, 2015 2:53 AM
    Moderator
  • When I do table update I lose the font formatting properties like font name though size seems to be sticking. Here is my code.

    Style taoStyle = application.ActiveDocument.Styles["Table of Authorities"];
             taoStyle.Font.Size = toa.ToaEntryFont.FontSize;
             taoStyle.Font.Name = toa.ToaEntryFont.FontName;
             taoStyle.Font.Italic = toa.ToaEntryFont.Italics;
             taoStyle.Font.Bold = toa.ToaEntryFont.Bold;
             taoStyle.Font.Underline = toa.ToaEntryFont.Underline.ToWordEnum();

             Style taoHeaderStyle = application.ActiveDocument.Styles["TOA Heading"];
             taoHeaderStyle.Font.Size = toa.ToaHeadingFont.FontSize;
             taoHeaderStyle.Font.Name = toa.ToaHeadingFont.FontName;
             taoHeaderStyle.Font.Italic = toa.ToaHeadingFont.Italics;
             taoHeaderStyle.Font.Bold = toa.ToaHeadingFont.Bold;
             taoHeaderStyle.Font.Underline = toa.ToaHeadingFont.Underline.ToWordEnum();

             foreach (TableOfAuthorities table in application.ActiveDocument.TablesOfAuthorities)
             {
                 var currentCat = toa.Categories.First(c => categoryDict[c.Heading] == table.Category);
                 //Get the TOAText for all citations in the current category and make it a queue for order of citations
                 var q = new Queue<String>(currentCat.Citations.Select(s => s.TOAText));
                 Paragraph paragraph = table.Range.Paragraphs.First;

                 while (q.Count > 0)
                 {
                     if (string.IsNullOrWhiteSpace(paragraph.Range.Text)
                         || toa.Categories.Any(c => c.Heading == paragraph.Range.Text.Replace("\r", "")))
                     {
                         //paragraph.Range.set_Style(taoHeaderStyle);
                         //AC is for Headings to always be double spaced
                            //paragraph.Range.set_Style(taoHeaderStyle);
                         paragraph.Format.LineSpacingRule = WdLineSpacing.wdLineSpaceDouble;
                         paragraph = paragraph.Next();
                     }
                     else
                     {
                         //Citation text
                         //Get the TOAText that we should be using next
                         string swap = q.Dequeue();
                         if (swap == null)
                         {
                             continue;
                         }
                         swap = swap.Trim();
                         //Reorder citation entries.
                         //Updating the range's text property resets the formatting.
                         //Wasn't able to find way to insert paragraph, or replace range with a range.
                         //Look for desired entry, then move it back to the correct position.
                         for (int i = 0; i <= q.Count; i++)
                         {
                             //Iterate forward until desired paragraph is found
                             //  swap is TOAText, and paragraph.Range.Text should be TOAText\t (page numbers)
                             if (paragraph.Range.Text.Contains(swap))
                             {
                                 while (i > 0)
                                 {
                                     //move paragraph backwards to correct position
                                     paragraph.Range.Relocate(0); //Relocate => 0=move up 1; 1=move down 1
                                     //Relocate calls paragraph.next, and we're moving the paragraph back 1
                                     //   move back 2 to navigate to same paragraph to move it back again
                                     paragraph = paragraph.Previous();
                                     paragraph = paragraph.Previous();
                                     i--;
                                 }
                                 break;
                             }
                             paragraph = paragraph.Next();
                         }

                         if (paragraph != null)
                         {
                             //Apply font formatting and other things from preferences
                             var formatting = paragraph.Format.Duplicate;
                             if (toa.LineSpacing == TrdfLineSpacing.Double)
                             {
                                 formatting.LineSpacingRule = WdLineSpacing.wdLineSpaceDouble;
                             }
                             paragraph.Range.ParagraphFormat = formatting;
                                //paragraph.Range.set_Style(taoStyle);
                             paragraph = paragraph.Next();
                         }
                         else
                         {
                             paragraph = table.Range.Paragraphs.First;
                         }
                     }
                 }
             }

    Monday, February 9, 2015 10:51 PM
  • Hi Arun33,

    Could you reset the font (e.g. font name) through UI directly?

    Could you reproduce that issue in a new project? If so, you may share a sample project on the OneDrive.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 10, 2015 2:37 AM
    Moderator
  • Hi,

    Do you solved your issue? Anything update will be appreciated.

    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, February 13, 2015 3:25 AM
    Moderator
  • Hi Arun,

    Unless you change the 'Table of Authorities' Style, any formatting changes you make to your Table of Authorities are liable to be lost next time you update it. The simplest way of updating the 'Table of Authorities' Style is to:
    • apply the existing 'Table of Authorities' Style to a temporary paragraph in your document
    • format the temporary paragraph as you want the 'Table of Authorities' entries to appear
    • right-click on the temporary paragraph and choose Styles>Update Table of Authorities Style to match selection.
    You might want to do the same for the 'TOA Heading' Style. Delete the temporary paragraph when you're done.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, February 13, 2015 5:04 AM
  • I couldn't fix this issue. Since font name and formatting doesn't stick after update, I have to re apply the font name while  applying formatting on the paragraphs. 

    If I do that my page numbers in the TOA goes off. I would need to apply correct style and also ensure the page numbers in the table of authorities are correct after applying the style (which might include increase/decrease in font size and also change in font properties (like bold italics and underline)

    Tuesday, February 24, 2015 2:43 AM
  • Hi,

    Could you reproduce that issue in a new project? If so, please share that sample project on the OneDrive.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 25, 2015 4:24 AM
    Moderator