我正在尝试使用以下代码更改整个文档的字体样式...
Word.run(function (context) {
const body = context.document.body;
body.font.set({
name: "Arial"
});
return context.sync();
})
.catch(function (error) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
};
});
在控制台中,出现以下错误:
Error: GeneralException: Cannot read property 'VA' of null
Debug info: {"code":"GeneralException","message":"Cannot read property 'VA' of null","errorLocation":"Font.name","statement":"font.name=...;","surroundingStatements":["var root=context.root;","var body=root.body;","// Instantiate {body}","var font=body.font;","// Instantiate {font}","// >>>>>","font.name=...;","// <<<<<"],"fullStatements":["Please enable config.extendedErrorLogging to see full statements."]}
任何帮助将不胜感激...
答案 0 :(得分:0)
我也在尝试理解该问题,这似乎是字体分配的问题。 我收到与相同的错误:
let inTextCit = context.document.getSelection().insertText('test', Word.InsertLocation.start);
inTextCit.font.size = 11;
context.sync()
如果我删除第二行代码,则不会发生错误。