Dzięki komentarzowi Serge'a i oryginalnemu wpisowi linku do wskazania mi właściwego kierunku. Oto co mam teraz:
var s = d.getHeader();
var logoResult = s.findText("{logo}"); // search result
var logoElement = logoResult.getElement(); // the paragraph that contains the placeholder
var text = logoElement.getText();
var placeholderStart = logoResult.getStartOffset(); // character position start placeholder
var placeholderEnd = logoResult.getEndOffsetInclusive(); // char. position end placeholder
var parent = logoElement.getParent();
var parPosition = parent.getChildIndex(logoElement);
// add new paragraph after the found paragraph, with text preceding the placeholder
var beforeAndLogo = s.insertParagraph(parPosition+2, text.substring(0, placeholderStart));
var logo = beforeAndLogo.appendInlineImage(logoBlob); // append the logo to that new paragraph
// add new paragraph after the new logo paragraph, containing the text after the placeholder
var afterLogo = s.insertParagraph(parPosition+3, text.substring(placeholderEnd+1));
afterLogo.merge(); // merge these two paragraphs
// finally remove the original paragraph
parent.removeFromParent(); // remove the original paragraph
To nie jest kompletna, należy również skopiować wszystkie atrybuty. Co ważniejsze, nie kopiuje ustawień karty (np. Zakładki środkowej). Nie znalazłem sposobu na ustawienie pozycji tabulatora.
Widziałeś ten post? http://stackoverflow.com/questions/11211434/insert-image-into-a-specified-location –
czytaj również komentarze. –
Serge, post (i komentarze) określa wyszukiwany ciąg "MUSI być sam" w akapicie. Moje pytanie dotyczy łańcucha wyszukiwania * w środku * akapitu, gdzie * tylko * ta część jest zamieniana. Mój przykład nie ma problemu ze znalezieniem ciągu wyszukiwania, ale umieszcza obraz przed (lub po) całym akapitem, zamiast umieszczać go przed dokładnie takim ciągiem wyszukiwania. – wivku