小编use*_*736的帖子

在google API脚本中获取findtext的子索引

我的目标是使用其他文档的内容替换Google云端硬盘文档中的一段文字.

我已经能够将文档插入到另一个文档中的某个位置,但是我无法确定要替换的文本的子索引.这是我到目前为止:

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 ) { …
Run Code Online (Sandbox Code Playgroud)

google-apps-script

5
推荐指数
1
解决办法
2434
查看次数

标签 统计

google-apps-script ×1