none
fixe usable font list ? RRS feed

  • Question

  • Hello

    I am currently developing an application level add-in for Word in C# and I would like to use it to restrict the available font list in the application...

    Can someone help me ?

    for example I want that when my add-in is loaded(on application startup), only Arial Black in 11pt can be used/selected to produce a document.

    So how can I "hide" the other fonts and sizes usually in the list in my addin startup function?

    I don't see which element of the "Microsoft.Office.Interop.Word.Application" object I need to deal with in order to implement this kind of restrictions...

    Thank you for your help.

    Tuesday, December 17, 2013 2:37 PM

Answers

  • Hi Yan

    Basic information on customizing the Ribbon can be found in a three-part article; the first part:
    http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx

    Information on implementing a Ribbon in a VSTO add-in (just the technical part, not the Ribbon XML required) can be found in the VSTO documentation.

    After you get a feel for the basics on of working with Ribbon XML you need to concentrate first on re-purposing built-in commands (you'll find a section on this in the three-parter). You need to identify the commands you want to control - you need their idMso values. In a <commands> section of your Ribbon XML you can then list these commands, one by one, and indicate whether to disable them or point them at your custom code.

    You may also want to construct your own "Fonts" group in the Ribbon in order to replace Word's built-in group. In that case, you'll also want to define this group in your Ribbon XML.

    <<But I wonder how will a document made with a "full version" of a Word will look like on a restricted version...>>

    There shouldn't be any difference, outside of the constraints you impose by limiting the formatting. This goes for both suggetstions (1) and (2). All you'll be doing is limiting the resources available to the users for applying formatting. This won't affect how Word creates, manages or produces documents.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Sood fr Friday, December 20, 2013 9:47 AM
    Wednesday, December 18, 2013 3:11 PM
    Moderator

All replies

  • It is not possible to change the font list Word offers as the list is hard-coded to pick up the fonts provided by Windows.

    You could:

    1. Provide a Ribbon customization that removes or disables the various FONT commands from the user interface and provide your own. Please note that a) this will do so for ALL documents and b) it could be overridden by another add-in

    2. Activate formatting restriction in documents, or, if this is a corporate environment, set up all templates used by the company with this in-place. Formatting restriction can be set up to allow the user to work only with the STYLES allowed for the document/template. This is actually an end-user topic which would be better pursued in the TechNet forum. In any case, such a discussion requires knowing the version of Word being used to set up the templates.


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, December 18, 2013 9:14 AM
    Moderator
  • Hi,

    >>So how can I "hide" the other fonts and sizes usually in the list in my addin startup function?<<

    I’m afraid you cannot disable other fonts in Word Fonts list except removing these font from OS.

    For a workaround, I suggest you changing the font and the size as you want automatically before saving the document with Document.BeforeSave Event in the Word add-in.

    Here is a sample to set the font as “Arial” and size as “14” for your reference.

    private void DocumentBeforeSave()
    {
        Document vstoDoc = Globals.Factory.GetVstoObject(Globals.ThisAddIn.Application.ActiveDocument);
        vstoDoc.BeforeSave += new Microsoft.Office.Tools.Word.SaveEventHandler(ThisDocument_BeforeSave);
    }
    
    void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e)
    {
        Word.Document document = Globals.ThisAddIn.Application.ActiveDocument;
        for (int i = 1; i <= document.Paragraphs.Count; i++)
        {
            Word.Range rng = document.Paragraphs[i].Range;
            rng.Font.Size = 14;
            rng.Font.Name = "Arial";
        }
    }

    Here is an article about setting the default font for your reference: How to set the default font in Word


    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, December 18, 2013 11:13 AM
    Moderator
  • Hello.

    I forgot that : I am working on Office (word) 2007. and Visual 2010.

    Thank you Luna

    I already thought about this kind of post-treatment but it isn't possible as there is a risk to modify the global document layout when you do that (simply changing a font size already transform the document view...) I want to let the user create the document he wants but only with the tools I want him to use...

    Thank you Cindy,

    I think the option (1) is the one I will then try to implement... can you point me to a good place from where I can start searching on this ?

    But I wonder how will a document made with a "full version" of a Word will look like on a restricted version...

    Once again thank you for your help...

    Wednesday, December 18, 2013 1:37 PM
  • Hi Yan

    Basic information on customizing the Ribbon can be found in a three-part article; the first part:
    http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx

    Information on implementing a Ribbon in a VSTO add-in (just the technical part, not the Ribbon XML required) can be found in the VSTO documentation.

    After you get a feel for the basics on of working with Ribbon XML you need to concentrate first on re-purposing built-in commands (you'll find a section on this in the three-parter). You need to identify the commands you want to control - you need their idMso values. In a <commands> section of your Ribbon XML you can then list these commands, one by one, and indicate whether to disable them or point them at your custom code.

    You may also want to construct your own "Fonts" group in the Ribbon in order to replace Word's built-in group. In that case, you'll also want to define this group in your Ribbon XML.

    <<But I wonder how will a document made with a "full version" of a Word will look like on a restricted version...>>

    There shouldn't be any difference, outside of the constraints you impose by limiting the formatting. This goes for both suggetstions (1) and (2). All you'll be doing is limiting the resources available to the users for applying formatting. This won't affect how Word creates, manages or produces documents.


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Sood fr Friday, December 20, 2013 9:47 AM
    Wednesday, December 18, 2013 3:11 PM
    Moderator
  • Hi Cindy

    I'll have a look at those documents and will try to figure out how to adapt my code accordingly. I believe I will be able to find what I need from there...

    Thank you for all this.

    Friday, December 20, 2013 9:47 AM