Il mio obiettivo è sostituire una parte di testo in un documento di Google Drive con il contenuto di un altro documento.Ottieni l'indice child di findtext nello script API di google
Sono stato in grado di inserire il documento in una determinata posizione nell'altro documento, ma ho difficoltà a determinare l'indice secondario del testo che voglio sostituire. Ecco quello che ho finora:
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);
}
}
};
Qualsiasi aiuto sarebbe molto apprezzato.
Quando c'è un'immagine in linea prima della posizione findText, dà l'indice figlio del paragrafo prima l'immagine, non dopo che l'immagine come necessario. C'è una soluzione? –