Search code examples
ms-wordoffice-jsadd-in

How to set table header background colour using office js


I am working on Office JS word addin project. I am creating a table with 4 columns and few rows. I want to set background colour of table header column to RED. How can I achieve this? Below is a sample code I am using for table creation.

function createTable() {    
  Word.run(function (context) {
    var body = context.document.body;
    var Table = body.insertTable(2, array.length, Word.InsertLocation.start, [array]);    
    return context.sync();
  })
  .catch(errorHandler);
}

Solution

  • Updated answer: To programmatically style a table in Word, use the Table.styles or Table.styleBuiltIn properties. You could also try the TableRow.shadingColor property.