У нас есть надстройка для документов, где она вставляет данные в документ, мы также хотели бы удалить текст, когда вы снова нажмете кнопку , как переключатель. Как сейчас, при нажатии на кнопку второй раз, в третий раз и т. Д., Он заполняет новый текст над уже существующим.Добавить текст и удалить текст в Документах Google (Add-on)
стороне клиента:
<div class="block" id="button-bar">
<button onclick="google.script.run.insertTextA();" id="TextA">Text A</button>
<button onclick="google.script.run.insertTextB();" id="TextB">Text B</button>
</div>
стороне сервера:
function insertTextA() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
text.insertText(11, 'There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..');
}
function insertTextB() {
var body = DocumentApp.getActiveDocument().getBody();
var text = body.editAsText();
text.insertText(12, 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old..');
}
Что вы пытаетесь удалить? –