Word.InsertLocation
のオプションは次のとおりです。
Start
:前に、既存のコンテンツを挿入されたコンテンツを付加します。
End
:の後にの内容を追加します。 Replace
:既存のコンテンツを挿入されたコンテンツに置き換えます。
bodyObject.insertFileFromBase64
を使用している場合は、ドキュメントの本文全体にスコープが設定されています。したがって、このメソッドを呼び出すと、カーソル位置が気になりません。
あなたが本当にここにほしいと思うのはrangeObject.insertFileFromBase64
です。これは、ボディ全体ではなく範囲にスコープされます。現在の選択範囲から範囲を取得することができます(またはカーソル位置が選択されていない場合)。
Word.run(function (context) {
// Queue a command to get the current selection and then
// create a proxy range object with the results.
var range = context.document.getSelection();
// Queue a commmand to insert base64 encoded .docx at the beginning of the range.
// You'll need to implement getBase64() to make this work.
range.insertFileFromBase64(getBase64(), Word.InsertLocation.start);
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function() {
console.log('Added base64 encoded text to the beginning of the range.');
});
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
WOW、その動作は絶対良好です。おかげであなたは私を救った。 –