2

I am trying to create a table in word document using Office Js.

I need to set the width for the two columns at 20% resp. 80%.

The table header should be formatted with a background color.

enter image description here

I tried using this code

var Table = body.insertTable(2, array.length, Word.InsertLocation.start, [array]); 
Table.styleBuiltIn = Word.Style.GridTable1Light_Accent1

I can't find the correct properties.

The entire function

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);
}
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Common_Coder
  • 131
  • 6
  • The Table object has a `shadingColor` property, but I'm not sure if that's what you want. The TableCell object has a `columnWidth` property. You might try setting that for a cell in the column. You should also look at the Table object's `style` and `builtinStyle` properties. – Rick Kirkham Oct 16 '19 at 18:32
  • Hi @RickKirkham i added the screenshot i m trying achieve that.I tried Style and Builtinstyle with different values nothing seems to be working. Please find the sample code which i tried var Table = body.insertTable(2, array.length, Word.InsertLocation.start, [array]); Table.styleBuiltIn = Word.Style.GridTable1Light_Accent1; – Common_Coder Oct 17 '19 at 10:14
  • Please describe how the code you have for formatting the table is not working. When I test it here (replacing the array information since I don't have that with static values) a formatted table is inserted. The colors are not the same as in the picture, but that's because the style name you use is not the same as the picture. – Cindy Meister Oct 17 '19 at 18:27
  • As for the column widths, please ask this as a new question. The Word JS APIs apparently do not support this (yet), which means a OOXML approach... – Cindy Meister Oct 17 '19 at 18:48

0 Answers0