Fonts not applying in Spreadjs using NodeJs

Posted by: Arasudayan.Anand on 20 September 2018, 5:09 am EST

    • Post Options:
    • Link

    Posted 20 September 2018, 5:09 am EST

    Hi Team,

    While generating spreadjs Json string using nodejs, everything is working fine but only

    fonts are not applying .

    i’m attaching sample code. And generated JSON string.

    Please help me on this.


    var $ = require(“jquery”);

    var angular = require(‘node-each’);

    var http = require(‘http’);

    var webfont = require(‘webfont’);

    var mockBrowser = require(‘mock-browser’).mocks.MockBrowser

    var qs = require(‘querystring’);

    global.window = mockBrowser.createWindow()

    global.document = window.document

    global.navigator = window.navigator

    global.HTMLCollection = window.HTMLCollection

    global.getComputedStyle = window.getComputedStyle

    var GC = require(‘@grapecity/spread-sheets’);

    GC.Spread.Sheets.LicenseKey = “”;

    var spreadNS = GC.Spread.Sheets;

    var doc = global.document;

    http.createServer(function (req, res) {

    var div = doc.createElement(‘div’,{id:‘excelSheets’});

     spread = new GC.Spread.Sheets.Workbook(doc.getElementById('excelSheets'), {
         sheetCount: 1
     });
    
    var sheet = spread.getActiveSheet();
    
    var style= new GC.Spread.Sheets.Style();
    
    style.font = "bold 10pt";
    
    sheet.setStyle(2,2, style,GC.Spread.Sheets.SheetArea.viewport);
    
    var json = spread.toJSON();
    
    console.log(JSON.stringify(json));
    
    var resStr="HEPP";
    res.writeHead(200, {'Content-Type': 'text/html'});
        res.end(json);
    

    }).listen(8080);

  • Posted 20 September 2018, 10:47 pm EST

    Hello,

    It seems the JSON is not not attached. Please attach the same and so I can open it in SpreadJS to debug further.

    Thanks,

    Deepak Sharma

  • Posted 24 September 2018, 1:31 am EST

    JSON created from Node.js:

    {

    “version”:“11.1.0”,

    “sheets”:{

    “Sheet1”:{

    “name”:“Sheet1”,

    “theme”:“Office2007”,

    “data”:{

    “dataTable”:{

    “1”:{

    “1”:{

    “value”:“madhu”,

    “style”:{

    “font”:“normal 15px normal normal normal normal”

    }

    }

    }

    },

    “defaultDataNode”:{

    “style”:{

    “themeFont”:“Body”

    }

    }

    },

    “rowHeaderData”:{

         },
         "colHeaderData":{  
    
         },
         "selections":{  
            "0":{  
               "row":0,
               "rowCount":1,
               "col":0,
               "colCount":1
            },
            "length":1
         },
         "index":0
      }
    

    }

    }

    JSON Created by Spread when Made as BOLD

    {

    “version”:“11.2.3”,

    “sheets”:{

    “Sheet1”:{

    “name”:“Sheet1”,

    “activeRow”:1,

    “activeCol”:1,

    “theme”:“Office2007”,

    “data”:{

    “dataTable”:{

    “1”:{

    “1”:{

    “value”:“madhu”,

    “style”:{

    “font”:“700 15px "normal normal normal normal"”

    }

    }

    }

    },

    “defaultDataNode”:{

    “style”:{

    “themeFont”:“Body”

    }

    }

    },

    “rowHeaderData”:{

    “defaultDataNode”:{

    “style”:{

    “themeFont”:“Body”

    }

    }

    },

    “colHeaderData”:{

    “defaultDataNode”:{

    “style”:{

    “themeFont”:“Body”

    }

    }

    },

    “selections”:{

    “0”:{

    “row”:1,

    “rowCount”:1,

    “col”:1,

    “colCount”:1

    },

    “length”:1

    },

    “sheetAreaOffset”:{

    “left”:0,

    “top”:0,

    “_left”:0,

    “_top”:0

    },

    “index”:0

    }

    }

    }

    ======================================Compare.zip

  • Posted 24 September 2018, 11:44 pm EST

    Hello,

    I opened the json file(“proper.json”) given by you with online demo and saved it to json. I found that the file saved() is exactly same and when I opened the newly saved json file it again showed the result same as '“proper.json”. Please test this issue with the online demo:

    https://www.grapecity.com/en/demos/spread/JS/InspectorSample/

    Also I have attached the newly saved json here.

    Thanks,

    Deepak Sharmanewlysaved.zip

  • Posted 26 September 2018, 1:01 pm EST - Updated 3 October 2022, 2:07 am EST

    Hi Deepak,

    Please find attached image, there i highlighted like that font drop-down is selected with something “normal normal…” rather than selected with actual font.

  • Posted 28 September 2018, 12:00 am EST

    Hello,

    It shows “normal normal normal…” since the JSON file you provided has this font in style element.

    Which I believe is correct behavior.

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels