Доброе утро,
Я надеюсь, что кто-то может помочь мне с этим вопросом.На самом деле я добавляю закладки в документ Google с помощью функции в Google Apps Script, документ имеет 160 страниц.Проблема в том, что код, который обновляет документ, завершает выполнение, документ все еще обновляется, и когда я проверяю файл, некоторые из закладок отображаются следующим образом:
Figure1. Figure2. "Text of the Figure 1"
Я пытался использовать службу LockServiceдля параллелизма, но я все еще получаю тот же результат.С документами, которые имеют только 20 страниц или меньше, у меня нет никаких проблем.(Я использую закладки в качестве заголовков внутри документа)
Краткое описание кода для обновления закладок:
function updateBookmarks() {
var document = DocumentApp.openById("1dQSHAL5v-cIDo9q8hon41XDaefxmztSQ-TVcYhg2sqI");
var markerPosition, regExpTitle;
var allBookMarks = document.getBookmarks();
// List of ordered bookmarks
var myBookmarks = [], bookmarkObject, i;
// Look over each bookmark
for (i = 0; i < allBookMarks.length; i++) {
//Obtain the position of the current bookmark
markerPosition = allBookMarks[i].getPosition();
if (markerPosition.getSurroundingTextOffset() > 0) {
// Initilize the object
bookmarkObject = {};
// Obtain the object of the bookmark
bookmarkObject.element = markerPosition.getElement();
// Obtain the ChildIndex
bookmarkObject.childIndex = getChildIndeByMarker_(bookmarkObject.element);
// Obtain the element of the bookmark as text
bookmarkObject.markerElementByText = bookmarkObject.element.asText();
// Obtain the text
bookmarkObject.text = bookmarkObject.markerElementByText.getText();
// Validate if the titles (bookmarks) have the format
regExpTitle = bookmarkObject.text.match(/ *(?:Figura \d+){1,}(\.|\. )/g);
if (regExpTitle) {
bookmarkObject.type = "figura";
// Obtain the text that will be replaced
bookmarkObject.replaceText = regExpTitle[0].replace("\.", "");
//markerElementByText.replaceText(searchPattern, "Figura " + titlesCount.figure);
myBookmarks.push(bookmarkObject);
}
// Validates if the titles (bookmarks) has the format
regExpTitle = bookmarkObject.text.match(/ *(?:Tabla \d+){1,}(\.|\. )/g);
if (regExpTitle) {
bookmarkObject.type = "tabla";
// Obtain the text that will be replaced
bookmarkObject.replaceText = regExpTitle[0].replace("\.", "");
//markerElementByText.replaceText(searchPattern, "Figura " + titlesCount.figure);
myBookmarks.push(bookmarkObject);
}
}
}
// Order the array by the position
myBookmarks.sort(sortArray);
var titlesCount = {
figure: 1,
table: 1
};
for (i = 0; i < myBookmarks.length; i++) {
switch (myBookmarks[i].type) {
case "figura":
myBookmarks[i].element.replaceText("^" + myBookmarks[i].replaceText, "Figura " + titlesCount.figure);
titlesCount.figure++;
break;
case "tabla":
myBookmarks[i].element.replaceText("^" + myBookmarks[i].replaceText, "Tabla " + titlesCount.table);
titlesCount.table++;
break;
}
}
// Save the changes in the document
document.saveAndClose();
}
Заранее спасибо.