I'm currently working in a Microsoft Excel add-in using TypeScript, and I'm facing some issues when trying to set a style. I need to set multiple of them to create a sheet template.
I tried to create the style directly but have issues when trying to set all borders to None
, as it requires me to load the object (and call await context.sync()
) even thou the style doesn't exist. I cannot assign it directly as the property is readonly
.
const styles = ctx.workbook.styles;
styles.add("newStyle");
const newStyle = styles.getItem("newStyle");
newStyle.borders.items.map(border => (border.style = "None"));
I've also tried to create it using the .set method and passing a JS object with the structure defined in StyleUpdateData
, but it also fails as well when trying to set the borders
property with the following RichAPI error:
Changes to property 'borders' cannot be applied through an "object.set" method.
Which would be the recommended way of creating a style when it includes border styling?
I have tried your scenario, the border.style is None when you create a new style, below is the code and repro step:
The code:
const styles = ctx.workbook.styles;
//styles.add("newStyle");
const newStyle = styles.getItem("newStyle");
newStyle.load('borders');
//newStyle.borders.items.map(border => (border.style = "None"));
await context.sync();
console.log(newStyle);
newStyle.borders.items.map(border => (border.style = "Continuous"));
await context.sync();
console.log(newStyle);
I print the value of style.border before and after change it's value. You can see that the value is None before you change it. And also the "set" operation works well.
Contact me if you have any other questions.