将幻灯片 pdf 保存到由 google 工作表单元格定义的文件夹中

Saving slides pdf into a folder defined by a google sheets cell

总体目标: 将我的 pdf 保存在我在 google 工作表单元格

中定义的文件夹中

我找到了这个脚本 ,我可以在其中将我的 google 幻灯片保存到 pdf 中,效果很好。

function pdf(){
var blob = DriveApp.getFileById("### Slide file ID ###").getBlob();
DriveApp.createFile(blob);
}

我想通过引用电子表格中的单元格来定义目标文件夹 ID。我想这将是我在此处找到的下面代码的变体 ?但我现在真的迷路了。

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const file_id = ss.getRange("Settings!B9").getValue(); // get value in "Settings!B9"
  const folder_id = ss.getRange("Settings!C9").getValue(); // get value in "Settings!C9"
  const googleDocTemplate = DriveApp.getFileById(file_id);
  const destinationFolder = DriveApp.getFolderById(folder_id)
}

我本以为它是这样的,但它仍然将 pdf 保存到我的驱动器的根文件夹中

function pdf() {
   const ss = SpreadsheetApp.openById("1j_Ltyx9e8Kb-ywLnJDLl5fzoWpfk3elD9xGvZX665DE");
  const folder_id = ss.getRange("Sheet1!C9").getValue(); // get value in "Sheet1!C9"
  const destinationFolder = DriveApp.getFolderById(folder_id)
  
  var blob = DriveApp.getFileById("1Jac6DZweMjiikCF5qvyZc367PRyn1RoUSs6Osy_F4n0").getBlob();
  DriveApp.createFile(blob);
  
}

您可以直接create文件夹内的文件:

function myFunction() {
  const ss = SpreadsheetApp.getActive();
  const file_id = ss.getRange("Settings!B9").getValue(); // get slides id
  const folder_id = ss.getRange("Settings!C9").getValue(); // get folder id
  const folder = DriveApp.getFolderById(folder_id)
  const blob = DriveApp.getFileById(file_id).getBlob();
  folder.createFile(blob); // create pdf file of the slide
}

确保幻灯片的文件 ID 位于 Settings!B9,文件夹 ID 位于 Settings!C9