google-apps-script - 将幻灯片 pdf 保存到由谷歌表格单元格定义的文件夹中
问题描述
总体目标:将我的 pdf 保存在我在 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);
}
解决方案
您可以直接在文件夹内创建文件:
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
.
推荐阅读
- windows - 找不到满足要求的版本
, 无匹配分布 - html - HTML正文不滚动
- docusignapi - 在 API 创建的信封完成后连接不记录来自回调 URL 的错误
- java - 将 Lettuce 与 RedisTemplate 一起使用会引发异常
- c# - c# 使用skip并接受从List派生的类
- google-colaboratory - 在 colab.research.google.com 中运行 retrain.py 的 TensorFlow 错误
- java - Wildfly 11 上的错误
- typescript - 如何在打字稿中将 C3 圆环图制作成半圆形或半圆环图?
- jquery - 单击不播放html5音频
- python - SqlAlchemy 与关联对象的多对多关系问题