Reputation: 37
I went through this documentation and followed the example mentioned here but not able to save document with filename. https://learn.microsoft.com/en-gb/javascript/api/word/word.document?redirectedfrom=MSDN&view=word-js-preview#save-- E.g.
// 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));
}
});
Any pointer would be great help.
Upvotes: 2
Views: 2607
Reputation: 9684
This is expected behavior. There isn't a "Save As" function yet, only "Save" so it follows Word's default rules for naming files. If the file has never been saved before, then the first line of text is used as the file name. As a workaround, consider programmatically adding the desired file name as the first line of text, saving the file, and then removing the first line.
Upvotes: 3