簡體   English   中英

在Google文檔中的特定位置插入文本

[英]Insert text at specific position in Google Docs

試圖將文本插入Google文檔。 我希望其格式如下:

在此處輸入圖片說明

文字1

空間

文字2

空間

我有以下代碼:

function InsertText1() {
   var body = DocumentApp.getActiveDocument().getBody();
   var text = body.editAsText();
   text.insertText(1, 'This is ju for test, lorem ipsum!');         

}

function InsertText2(){
   var body = DocumentApp.getActiveDocument().getBody();
   var text = body.editAsText();
   text.insertText(10, 'What test?, lorem ipsum!'); 
}

運行此程序的結果使我們獲得了文本中的文本,只是一團糟。 在此處輸入圖片說明

使用appendText而不是insertText,如下所示:

text.appendText('This is ju for test, lorem ipsum!\n');      

並添加“ \\ n”以添加“新行”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM