通过评论& amp;从Google文档到Google表格的建议编辑 [英] Pass Comments & Suggested Edits from a Google Document to a Google Sheet

查看:63
本文介绍了通过评论& amp;从Google文档到Google表格的建议编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

堆高车.我正在使用Google Apps脚本来(a)捕获Google文档中的所有注释" ... ...并且(b)将它们列出在Google表格的列中...

Fellow Stackers. I'm using a Google Apps Script to (a) capture all "Comments" in a Google Document... ...and (b) list them in a column of a Google Sheet...

但是,我想知道是否有可能...

However, I'm wondering if it's possible to...

(1)将注释"数组排列到工作表"中一列中的各个单元中,而不是像我现在所看到的那样成列.这是我目前用来获取评论内容的GAS:

(1) Array "Comments" into individual cells down a column in my Sheet rather than into a single column, as I have now. This is the bit of GAS I'm currently using to grab comment contents:

 var comments = JSON.parse(Drive.Comments.list(id));
 var items=comments.items;

 var string = "";
  for(var i in items){
    string+='\n';
    string+=items[i].content;
  }

(2)在我的Google文档中按锚点位置排序评论",即锚定在文档中最高的注释将出现在工作表列的第一个单元格中.

(2) Order the "Comments" by anchor position in my Google Document—i.e. the comment anchored highest in the doc would appear in the first cell of the Sheet's column.

(3)还要在我的Google文档中的注释旁边添加建议的编辑".可以通过API访问吗?

(3) Also include "Suggested Edits" from my Google Document alongside the comments. Can those be accessed via API yet?

在此先感谢任何可能提供帮助的人!

Thanks in advance to anyone who may be able to help!

  • Google Document: https://docs.google.com/document/d/1O7zAdkCmxhYihtfJhZ3OGkWfO8UUJ_deoHEYr7rQHW4/edit?usp=sharing
  • Google Apps Script: https://script.google.com/macros/d/1MgTtU0cKSS_XghRjAMtjZFQAdsbU9SkD_2zx03KVKb1Vy4iBBp3MI2QW/edit?uiv=2&mid=ACjPJvHY-vp53Ek1wBR4-W3Q1Ur8dSdyN0g6ZI7n3I48-e7EWyq6v9gY82OAeVNlnpQBbY3ICOzi4PCRtp-pjuqAbH3oePLelcIp-YUPs2FNbB7Cl7CC-AvgnoJPcXCnrO8CrIJEI2v8ns8&splash=yes
  • Google Sheet: https://docs.google.com/spreadsheets/d/1uAtmAO0we7h3HUAFlDBLXlShSLvHVM_W6OSXPwpX_t8/edit?usp=sharing

推荐答案

(1)将数组注释"排列到工作表中一列中的单个单元格中,而不是像现在这样单个列中.

(1) Array "Comments" into individual cells down a column in my Sheet rather than into a single column, as I have now.

这段代码将注释数组,并将它们串联成一个字符串:

This bit of code is taking an array of comments, and concatenating them into a single string:

  var string = "";
  for(var i in items){
    string+='\n';
    string+=items[i].content;
  }

为了能够将每个注释放入一列中的单独单元格中,您需要将该数组更改为二维数组,并且每个原始元素都位于其自己的行"中.像这样:

To be able to put each comment into a separate cell in a column, you need to change that array into a 2-dimensional array, with each of the original elements in its own "row". Something like:

  var data = [];           // start with an empty array
  for (var i=0; i<items.length; i++) {
    var item = items[i];   // current comment
    // A row is an array of cells
    var row = [item.htmlContent,item.author.displayName,item.createdDate];
    data.push(row);        // Add this row to the data array
  }

此行写单个单元格的内容,尽管使用setValues()可以填充矩形范围:

This line writes the content of a single cell, albeit using setValues() which can fill a rectangular range:

var targetRange = sheet.getRange(lastRow+1,1,1,1).setValues([[string]]);

使用之前创建的二维数组,您可以像这样追加到工作表:

With the 2-D array created earlier, you can append to the sheet like so:

var targetRange = sheet.getRange(lastRow+1,1,data.length,data[0].length);
targetRange.setValues(data);

结果:

function driveApiComment(id){

  var comments = JSON.parse(Drive.Comments.list(id));
  var items=comments.items;

  var data = [];           // start with an empty array
  for (var i=0; i<items.length; i++) {
    var item = items[i];   // current comment
    // A row is an array of cells
    var row = [item.htmlContent,item.author.displayName,item.createdDate];
    data.push(row);        // Add this row to the data array
  }

  var sheet = SpreadsheetApp.openById(submissionSSKey).getSheets()[0];
  var lastRow = sheet.getLastRow();
  var targetRange = sheet.getRange(lastRow+1,1,data.length,data[0].length);
  targetRange.setValues(data);

}

(2)在我的Google文档中按锚点位置排序评论",即锚定在文档中最高的注释将出现在工作表列的第一个单元格中.

(2) Order the "Comments" by anchor position in my Google Document—i.e. the comment anchored highest in the doc would appear in the first cell of the Sheet's column.

您不走运(至少现在是这样).参见:

You're out of luck (for now, at least). See:

  • How to match comments on an image using kix anchor (or not) in Google Docs
  • Anchor documentation does not exist?
  • Creating anchored comments programmatically in Google Docs

摘要:Google的定位标记不可识别. (就像它们是隐藏数据库的密钥一样,该数据库包含对文档的实际行和字符引用以及您的社会保险号和母亲的娘家姓.)您可以检索它们&按字母顺序对它们进行排序...但这与注释在文档中的显示位置无关.

Summary: Google's anchors are not decipherable. (Likely they are a key to a hidden database that includes the actual line & char refs to your document, along with your social security number and mother's maiden name.) You could retrieve them & sort them alphabetically... but that would have no relation to where the comments appear in a document.

(3)还要在我的Google文档中的注释旁边添加建议的编辑".可以通过API访问吗?

(3) Also include "Suggested Edits" from my Google Document alongside the comments. Can those be accessed via API yet?

不.

这篇关于通过评论&amp; amp;从Google文档到Google表格的建议编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆