【问题标题】:Saving slides pdf into a folder defined by a google sheets cell将幻灯片 pdf 保存到由谷歌表格单元格定义的文件夹中
【发布时间】:2021-02-20 08:17:22
【问题描述】:

总体目标: 将我的 pdf 保存在我在 google 表格单元格中定义的文件夹中

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

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

我想通过引用电子表格中的单元格来定义目标文件夹 ID。我想这将是我在How to reference a cell as the file or folder id for DriveApp 找到的下面代码的变体?但我现在真的迷路了。

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);
  
}

【问题讨论】:

    标签: google-apps-script google-sheets google-drive-api google-slides


    【解决方案1】:

    您可以直接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 中。

    【讨论】:

    • 谢谢它可以将文件从正确的文件夹移动,有没有办法在第一个实例中将 pdf 保存到指定的文件夹。我将保存很多文件,我不希望将其保存到驱动器的根文件夹中。谢谢!
    • 或者,如果我可以自动检索 pdf 的 url 并将其注入电子表格。谢谢!
    • @Mee 请检查我更新的代码。我使用了您的第一种方法,并使其将文件创建到特定文件夹。文件夹 ID 和幻灯片 ID 由电子表格中的单元格给出。我希望这是您想要遵循的方向。
    • 你太棒了!它就像我想要的那样工作。你救了我好几次,我真的很感激!
    • @Mee 很高兴它对你有帮助:)
    猜你喜欢
    • 1970-01-01
    • 2022-09-23
    • 2019-05-12
    • 2023-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多