私の目標は、Googleドライブのドキュメントのテキストを別のドキュメントのコンテンツで置き換えることです。GoogleのAPIスクリプトでfindtextの子インデックスを取得
他のドキュメントの特定の位置にドキュメントを挿入できましたが、置換するテキストの子インデックスを特定できませんでした。これまで私が持っているものは次のとおりです。
function replace(docId, requirementsId) {
var body = DocumentApp.openById(docId).getActiveSection();
var searchResult = body.findText("<<requirementsBody>>");
var pos = searchResult.?? // Here I would need to determine the position of the searchResult, to use it in the insertParagraph function below
var otherBody = DocumentApp.openById(requirementsId).getActiveSection();
var totalElements = otherBody.getNumChildren();
for(var j = 0; j < totalElements; ++j) {
var element = otherBody.getChild(j).copy();
var type = element.getType();
if(type == DocumentApp.ElementType.PARAGRAPH) {
body.insertParagraph(pos,element);
} else if(type == DocumentApp.ElementType.TABLE) {
body.insertTable(pos,element);
} else if(type == DocumentApp.ElementType.LIST_ITEM) {
body.insertListItem(pos,element);
} else {
throw new Error("According to the doc this type couldn't appear in the body: "+type);
}
}
};
ご協力いただければ幸いです。
FINDTEXT場所の前にインライン画像があり、それがない画像の後に、画像前の段落の子のインデックスを提供します。回避策はありますか? –