Changing the font of a cell which has a font

Posted by: datta on 27 May 2019, 8:09 am EST

    • Post Options:
    • Link

    Posted 27 May 2019, 8:09 am EST

    Hi I have a cell with style.font = ‘bold italic 10pt Calibri’ . Now if I need to just change the font-family of this font to Arial, keeping bold and italic intact then what is the best way to do it?

  • Posted 28 May 2019, 1:06 am EST

    Hi,

    You could use a temporary ‘span’ element to modify only part of the font string. Please refer to the following code snippet:

    // current font string
    style.font = 'bold italic 10pt Calibri';
    // update font family
    style.font = getModifiedFontString(style.font, 'fontFamily', 'monotype corsiva');
    // update font-weight
    style.font = getModifiedFontString(style.font, 'fontWeight', 500);
    
    function getModifiedFontString(fontString, attrib, newValue){
    	var el = document.createElement('span');
    	el.style.font = fontString;
    	el.style[attrib] = newValue;
    	return el.style.font;
    }
    

    ~sharad

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels