none
wanting to put text before the bibliography RRS feed

  • Question

  • Hi,

    I have a code here that insert a bibliography but what I want is to put a bold text before inserting it in the document

    by the way here is the code

    wordApplication.Selection.EndKey(ref paramWdUnits, ref paramWdMovementType);
                wordApplication.Selection.InsertBreak(WdBreakType.wdPageBreak);
    
    
                bool isFoundFieldBibliography = false;
                foreach (Field field in wordApplication.ActiveDocument.Range().Fields)
                {
                    if (field.Type == WdFieldType.wdFieldBibliography)
                    {
                        isFoundFieldBibliography = true;
                        field.Update();
                    }
                }
                if (!isFoundFieldBibliography)
                {
    
    
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
                }

    I hope someone knows how

    more power

    God Bless us all.

    • Changed type iGnjmz Tuesday, February 11, 2014 11:50 PM
    • Moved by Marvin_Guo Wednesday, February 12, 2014 1:14 AM Word related
    Tuesday, February 11, 2014 12:33 PM

Answers

  • Hi,

    Try to use the InsertBefore() method before you add bibliography field .The InsertBefore() method

    Inserts the specified text before the specified range with the same format.

    Here is a code sample and screenshot:

                Application wordApplication = Globals.ThisAddIn.Application;
                Range rng = wordApplication.Selection.Range;
                wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
                rng.InsertBefore("Reference ");
                rng.Font.Bold = -1;
                rng.Font.Size = 20;
    

    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.

    • Marked as answer by iGnjmz Thursday, February 13, 2014 2:28 PM
    • Unmarked as answer by iGnjmz Friday, February 14, 2014 12:46 PM
    • Marked as answer by iGnjmz Friday, February 14, 2014 12:46 PM
    Thursday, February 13, 2014 9:42 AM

All replies

  • Hi,

    Based on my understanding, I think you want to insert bibliography with bold font, you can create new style in document, and set style of bibliography field.

    The following code sample creates a character style called In-Text Bibliography if it does not yet exist. When the style is newly created, it sets the font to bold. Then the style is applied to all bibliography fields in the document. Text bibliography, you can update the formatting for all bibliographies later.

                Style style;
                bool exists =false ;
                string stylename ="In-Text Bibliography";
                foreach (Style s in wordApplication.ActiveDocument.Styles)
                {
                    if (s.NameLocal == stylename)
                        exists = true;
                }
                if (exists == false)
                {
                    style = wordApplication.ActiveDocument.Styles.Add(stylename);
                    style.Font.Bold = -1;
    
                }
    //…Insert Bibliography
                foreach (Field  fld in wordApplication.ActiveDocument.Fields )
                {
                    if (fld.Type == WdFieldType.wdFieldBibliography)
                    {
                        fld.Select();
                        wordApplication.Selection.set_Style(wordApplication.ActiveDocument.Styles["In-Text Bibliography"]);
    
                    }
                }
    
    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.

    Wednesday, February 12, 2014 8:44 AM
  • Hi,

    I have a code here that Insert a Text and a bibliography but the problem is the Text is being Inserted after the Bibliography and what I want is the text should be inserted before the Bibliography..

    I hope someone knows how to fix this

    by the way here's my code.

    bool isFoundFieldBibliography = false;
                foreach (Field field in wordApplication.ActiveDocument.Range().Fields)
                {
                    if (field.Type == WdFieldType.wdFieldBibliography)
                    {
                        isFoundFieldBibliography = true;
                        field.Update();
                    }
                }
                if (!isFoundFieldBibliography)
                {
                    Word.Range rng = wordApplication.Selection.Range;
                    rng.Text = "Reference";
                    rng.Font.Bold = -1;
                    rng.Font.Size = 20;
                    rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
                }

    Thank you in advance

    More Power Guys

    God Bless us all.

    • Merged by Marvin_Guo Wednesday, February 12, 2014 11:23 AM The same
    Wednesday, February 12, 2014 10:04 AM
  • Hi Sir Marvin,

    The description of my question is not right and I'm sorry for that Sir and because of that Sir I updated my question to this Sir

    here's the link sir

    http://social.msdn.microsoft.com/Forums/office/en-US/3dbd51ca-be36-4e57-bb86-744226a850f9/insert-the-text-before-the-bibliography?forum=worddev#3dbd51ca-be36-4e57-bb86-744226a850f9

    I hope you will help me Sir.

    Wednesday, February 12, 2014 10:48 AM
  • Hi,

    >>I want is the text should be inserted before the Bibliography..

    If you want insert text before Bibliography field.You can use the Selection.InsertBefore() method to insert text before your selection range.

    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.

    Wednesday, February 12, 2014 11:37 AM
  • Hi Sir Marvin,

    what do you mean Sir?

    like this?

    Word.Range rng = wordApplication.Selection.Range;
    
                    rng.InsertBefore("Reference");
                    rng.Font.Bold = -1;
                    rng.Font.Size = 20;
                    rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
                    wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                    ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);

    Wednesday, February 12, 2014 3:56 PM
  • Hi,

    Try to use the InsertBefore() method before you add bibliography field .The InsertBefore() method

    Inserts the specified text before the specified range with the same format.

    Here is a code sample and screenshot:

                Application wordApplication = Globals.ThisAddIn.Application;
                Range rng = wordApplication.Selection.Range;
                wordApplication.Selection.Fields.Add(wordApplication.Selection.Range,
                ref paramWdFieldTypeBiblio, ref paramMissing, ref paramMissing);
                rng.InsertBefore("Reference ");
                rng.Font.Bold = -1;
                rng.Font.Size = 20;
    

    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.

    • Marked as answer by iGnjmz Thursday, February 13, 2014 2:28 PM
    • Unmarked as answer by iGnjmz Friday, February 14, 2014 12:46 PM
    • Marked as answer by iGnjmz Friday, February 14, 2014 12:46 PM
    Thursday, February 13, 2014 9:42 AM
  • Hi Sir Marvin,

    your code helps Sir so I will mark it as answer and I add few codes Sir so that the first text in the bibliography field will not be insert next to text reference

    this is the code I add

    wordApplication.Selection.InsertBreak(WdBreakType.wdLineBreak);

    now the last thing I need is to put the text Reference in the Center like the image below

    can you still help me with this Sir Marvin? pls..

    Thursday, February 13, 2014 2:38 PM
  • Hi Sir Marvin,

    Can you still help me with this?

    Friday, February 14, 2014 12:49 PM
  • Hi Sir Marvin,

    Thank you I already fix my problem.

    More Power to you God Bless us all.

    Saturday, February 15, 2014 3:01 PM