可以使用Google App Script中的Drive API和Sheets API来实现这个任务。以下是一个简单的代码示例,可以将指定的选项卡从电子表格中复制,将复制的选项卡转换为PDF文件,然后将其保存到指定的Google Drive文件夹中。
function duplicateAndSaveAsPDF() {
// get the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get the sheet you want to copy
var sheetToCopy = ss.getSheetByName("Name of Sheet to Copy");
// duplicate the sheet
var newSheet = sheetToCopy.copyTo(ss).setName("New Name for Duplicated Sheet");
// export the new sheet as pdf
var url = ss.getUrl();
url = url.replace(/edit$/,'');
var pdfFile = DriveApp.createFile(newSheet.getAs('application/pdf')).setName("Name of PDF File");
var folder = DriveApp.getFolderById("ID of Folder to Save PDF File");
folder.addFile(pdfFile);
// delete the new sheet
ss.deleteSheet(newSheet);
}
请替换示例中的以下值,以适应您的需要:
请注意,您需要在Google Cloud Platform中启用Google Drive API和Google Sheets API才能使用此代码。您还需要对此代码进行修改才能保证其和您的实际需求相符。