none
Format an excel cell RRS feed

  • Question

  • Hi,

    I was just wondering if the API allows you to format a cell using javascript. If not, will this capability be added for Excel 2013 or will we have to wait until the next version of Office?

    Thanks,

    Geoff

    Sunday, August 26, 2012 6:56 PM

Answers

  • Hi, Geoff

    It's not possible to modify cell/text color or font using the JavaScript API for Office. You can add number formatting by writing values such as "$1,000.00" or "8/27/2012" to cells. For example, if you enter a dollar amount, Excel will recognize it and add the $ sign and appropriate punctuation to future values that you write to the cell.

    We don't have plans to add color/font formatting control in the API for Office 2013. For this release we were focused on getting a core set of APIs that work the same way on many Office applications and that are compatible with future releases. Adding color/font formatting is a common request, so we will consider building that feature for future versions of Office.

    Depending on the solution you want to deliver, it might make sense to create an Excel template that uses your app. Then you could apply Excel's conditional formatting so that cell/text color changes depending on the data.

    Thanks for the question, and let us know if you have more!

    -Michael

        

    Monday, August 27, 2012 6:24 PM
    Moderator

All replies

  • Hi, Geoff

    It's not possible to modify cell/text color or font using the JavaScript API for Office. You can add number formatting by writing values such as "$1,000.00" or "8/27/2012" to cells. For example, if you enter a dollar amount, Excel will recognize it and add the $ sign and appropriate punctuation to future values that you write to the cell.

    We don't have plans to add color/font formatting control in the API for Office 2013. For this release we were focused on getting a core set of APIs that work the same way on many Office applications and that are compatible with future releases. Adding color/font formatting is a common request, so we will consider building that feature for future versions of Office.

    Depending on the solution you want to deliver, it might make sense to create an Excel template that uses your app. Then you could apply Excel's conditional formatting so that cell/text color changes depending on the data.

    Thanks for the question, and let us know if you have more!

    -Michael

        

    Monday, August 27, 2012 6:24 PM
    Moderator
  • UPDATE: You can now format cells through the Apps for Office Javascript API, though not in Excel Online (yet).
    Tuesday, June 3, 2014 5:29 PM
  • Hi Ian, Could you please post code for format cell through JavaScript API. It is not working for me.  I am using below code to format the cells.

     Office.context.document.bindings.addFromNamedItemAsync("Sheet1!A1:B1", "matrix", { id: "Sheet1B1" },
                    function (asyncResult) {
                        if (asyncResult.status == "failed") {
                            alert("not working...");
                        }
                        else {
                            // Write data to the new binding.
                            Office.select("bindings#Sheet1B1").setDataAsync([['abcd', 'efgh']], { coercionType: "matrix", cellFormat: [{format: {fontColor: "yellow"}}]},
                                function (asyncResult) {
                                    if (asyncResult.status == "failed") {
                                        alert("not working...");
                                    }
                                });
                        }
                    });

    Wednesday, April 1, 2015 2:15 PM
  • You can't format cells in Matrix bindings, only Table bindings. I'm not sure why -- this API has weird restrictions everywhere.

    Also, an update to my earlier post: you can now format cells in Table bindings in Excel Online.

    Wednesday, April 1, 2015 2:18 PM