如何解决在使用word加载项时,如何使用office js API或其他任何方式使用文件名保存word文档?
我仔细阅读了本文档,并遵循了此处提到的示例,但无法使用文件名保存文档。 https://docs.microsoft.com/en-gb/javascript/api/word/word.document?redirectedfrom=MSDN&view=word-js-preview#save-- 例如
// Run a batch operation against the Word object model.
Word.run(function (context) {
// Create a proxy object for the document.
var thisDocument = context.document;
// Queue a command to load the document save state (on the saved property).
context.load(thisDocument,'saved');
// Synchronize the document state by executing the queued commands,// and return a promise to indicate task completion.
return context.sync().then(function () {
if (thisDocument.saved === false) {
// Queue a command to save this document.
thisDocument.save();
// Synchronize the document state by executing the queued commands,// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log('Saved the document');
});
} else {
console.log('The document has not changed since the last save.');
}
});
})
.catch(function (error) {
console.log("Error: " + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
});
任何指针都会有很大帮助。
解决方法
这是预期的行为。还没有“另存为”功能,只有“保存”,因此它遵循Word命名文件的默认规则。如果以前从未保存过文件,则将文本的第一行用作文件名。解决方法是,考虑以编程方式将所需的文件名添加为文本的第一行,保存文件,然后删除第一行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。