Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

Insert the entire contents of one Google Doc into the comment of another

The problem I'm interested to know if it is possible to copy the entire contents of one Google Doc and paste into a comment in another Google Docs using keyboard commands.

Background- I do a lot of grading of student papers and have a range of standard comments I use which are individually stored in separate documents. I use Macros and keyboard shortcuts in MS Word to grab the contents of the comment file I want and put it into a comment in the paper I'm grading. I edit the macro files using the VB editor when necessary. It works quite efficiently.

I found some related material in my research, however this don't quite match what I am trying to do.

I think the code from here Insert comment into Google doc does something like what I want, but kind of the opposite.

Google Apps Scripts is new to me. I'm not really looking to become a programmer, I just need to know if developing such a script is possible or not and how hard it would be. I would appreciate being pointed in the right direction. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

A sample to point you into the right direction:

function myFuction()
{
  var fileOriginId='PASTE HERE THE ID OF THE FILE WITH THE COMMENT TEXT';
  var fileDestinationId ='PASTE HERE THE ID OF THE FILE WHERE THE COMMENTS SHALL BE INSERTED';
  var text=DocumentApp.openById(fileOriginId).getBody().getText()
  var comment={ 'content': text};
  Drive.Comments.insert(comment, fileDestinationId);
}

enter image description here

This code snippet passes the whole contents of a Google Docs document to the variable text. Subsequently, the contents of text is inserted as a comment into a second Google Docs document. It uses the Advanced Drive Service that needs to be enabled beforehand.

  • Should you desire to pass only a part of the text in the original file into the comment, e.g. a paragraph, you would need to chose the specific paragraph instead of the whole document body.
  • Should you desire to append the comment to a certain text within the destination document, you need to use the optional property context.value, as done in the reference you provided.

Please find here references to useful documentation that will help you udderstand Apps Script and adjust the code snippet provided to your requirements:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...