is it possible to change the font color similar as changing the background color .

is it possible to change the font color similar as changing the background color .

rsinghshahilrsinghshahil Posts: 1Questions: 1Answers: 0
edited May 2022 in Free community support

$(this).attr( "s", "24" ) => changes column to blue but not the font.
are there any ways.
this is what I have now.
$("row c[r^=A]", sheet).each(function ( index, element) {
if (index !== 0) {
$(this).attr( "s", "24" );
}
});

Answers

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited May 2022

    You would need to make your own font and / or style.

    As the docs say:

    This is only a brief summary of how to customise the XLSX files. Full details of the XLSX file format and its features are outside the scope of this documentation. Please refer to the Microsoft and Office Open XML documentation for details.

    You can also search the forum on how to do this. Other people and myself have posted examples.

    You can take a look at this: https://datatables.net/forums/discussion/72366/excel-export#latest

    You'll find this in there as well. It is about creating your own fonts, styles and number formats:

    customize: function( xlsx ) {
        var sSh = xlsx.xl['styles.xml'];
        var lastXfIndex = $('cellXfs xf', sSh).length - 1;           
        var lastFontIndex = $('fonts font', sSh).length - 1;
        var f1 = //bold and underlined font
        '<font>'+
                '<sz val="11" />'+
                '<name val="Calibri" />'+
                '<b />'+'<u />'+
        '</font>'
    
        var i; var y;
    //n1, n2 ... are number formats; s1, s2, ... are styles
        var n1 = '<numFmt formatCode="##0.0000%" numFmtId="300"/>';
        var s1 = '<xf numFmtId="300" fontId="0" fillId="0" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyNumberFormat="1"/>';
        //define the style with the new font (number passed in as a variable)
        var s2 = '<xf numFmtId="0" fontId="'+(lastFontIndex+1)+'" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">'+
                    '<alignment horizontal="center"/></xf>';        
        var s3 = '<xf numFmtId="0" fontId="2" fillId="2" borderId="0" applyFont="1" applyFill="1" applyBorder="1" xfId="0" applyAlignment="1">'+
                    '<alignment horizontal="center" wrapText="1"/></xf>'
        sSh.childNodes[0].childNodes[0].innerHTML += n1;  //new number format
        sSh.childNodes[0].childNodes[1].innerHTML += f1; //new font
        sSh.childNodes[0].childNodes[5].innerHTML += s1 + s2 + s3; //new styles
     
        var fourDecPlaces    = lastXfIndex + 1;
        var greyBoldCentered = lastXfIndex + 2;
        var greyBoldWrapText = lastXfIndex + 3;
    
  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406

    This comment should be helpful as well:

    // see built in styles here: https://datatables.net/reference/button/excelHtml5
    // take a look at https://cdn.datatables.net/buttons/2.2.2/js/buttons.html5.js , search for "xl/styles.xml"
    //styleSheet.childNodes[0].childNodes[0] ==> number formats  <numFmts count="6"> </numFmts>
    //styleSheet.childNodes[0].childNodes[1] ==> fonts           <fonts count="5" x14ac:knownFonts="1"> </fonts>
    //styleSheet.childNodes[0].childNodes[2] ==> fills           <fills count="6"> </fills>
    //styleSheet.childNodes[0].childNodes[3] ==> borders         <borders count="2"> </borders>
    //styleSheet.childNodes[0].childNodes[4] ==> cell style xfs  <cellStyleXfs count="1"> </cellStyleXfs>
    //styleSheet.childNodes[0].childNodes[5] ==> cell xfs        <cellXfs count="67"> </cellXfs>
    //on the last line we have the 67 currently built in styles (0 - 66), see link above
    
Sign In or Register to comment.