我在 Google 表格中有一份學生進度報告,它根據在單元格 B5 中輸入的唯一學生 ID 填充資料(使用查詢、過濾器、vlookup、迷你圖等)。作為一名教師,這對我來說非常有用,可以在螢屏上單獨向學生展示。但是,我的學校希望使用該報告與所有學生和家長進行交流。
對于一千名學生來說,這在邏輯上幾乎是不可能的。有沒有辦法撰寫一個腳本,在 B5 中自動輸入學生 ID,將其下載為 PDF 并用學生 ID 號命名檔案?然后為下一個學生證重復這個程序?
我一直在努力完成這項作業,現在在如何與學生和家長共享這些資訊方面遇到了困難(同時保護隱藏表中發現的全校資料的隱私等)。我知道如何處理公式,甚至更“高級”的公式,但撰寫腳本還不是我能做的事情。如果我能找到一個接近我想要完成的目標,我知道足以進行小的定制,但我真的迷失了這個。如果有人有任何想法或可以幫助我,我將不勝感激!
uj5u.com熱心網友回復:
這是一個草稿
function saveAllAsPDF(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sh1 = ss.getSheetByName('IMPORT Masterlist');
const sh2 = ss.getSheetByName('Student Progress Report');
sh1.getRange('A2:A' sh1.getLastRow()).getValues().flat().forEach(id => {
if (id != '') {
sh2.getRange('B5').setValue(id)
SpreadsheetApp.flush();
savePDF()
}
})
}
function savePDF(){
const folderID = '1N0AIh5oEszYw_NXKD0Vx1XrXUiPuUadR';
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sh = ss.getSheetByName('Student Progress Report');
const d = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "yyyy-MM-dd")
const filename = sh.getRange('B5').getValue() '_' d ".pdf"
const url = 'https://docs.google.com/spreadsheets/d/' ss.getId() '/export?';
const exportOptions =
'exportFormat=pdf&format=pdf'
'&size=A4'
'&portrait=true'
'&fitw=true'
'&sheetnames=false&printtitle=false'
'&pagenumbers=false&gridlines=false'
'&fzr=false'
'&gid=' sh.getSheetId();
var params = {method:"GET",headers:{"authorization":"Bearer " ScriptApp.getOAuthToken()}};
var response = UrlFetchApp.fetch(url exportOptions, params).getBlob();
DriveApp.getFolderById(folderID).createFile(response.setName(filename));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/487350.html
