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
294 views
in Technique[技术] by (71.8m points)

Get text from google sheet cell to a google doc

I have a google sheet which we create a new version every week with the sheet name updated. In this sheet we have a cell which has notes.The cell is fixed. How can I pull data from all sheets which lets says starts with Reporting Weekly gets the text from that cell and push it to a google doc.

question from:https://stackoverflow.com/questions/65599380/get-text-from-google-sheet-cell-to-a-google-doc

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

1 Reply

0 votes
by (71.8m points)
function copyNotes() {
  const prefix="Report Weekly";
  const fldrid="";//report folder id
  const name=Utilities.formatString('ReportSummary:%s',Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "E-yy.MM.dd.HH.mm.ss"));//you may wish to change name formatting for the new document
  const fldr=DriveApp.getFolderById(fldrid);
  const fileid=DocumentApp.create(name).getId();//creating the document
  const doc=DocumentApp.openById(fileid);//open document
  const notecell='A1';//The cell where the notes are found
  const ss=SpreadsheetApp.getActive();
  const shts=ss.getSheets().filter(s=>s.getName().startsWith(prefix));//filter out unwanted sheets
  shts.forEach(sh=>{doc.getBody().appendParagraph(sh.getRange(notecell).getValue())});//read notecells of all sheets and append to document
  doc.saveAndClose();//save document in root
  Drive.Files.update({"parents": [{"id": fldr.getId()}]}, fileid);//move to correct folder
}

Note: You will need to enable the advanced Drive API inorder to run this function.


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

...