image - 如何通过谷歌脚本将图像添加到谷歌文档并进行文本换行
问题描述
我有一个名为“logo.png”的图像保存在我的 Google 驱动器中。
我想将图像添加到 Google 文档中,使其位于左上角,并且不会扭曲其周围的文本。(换句话说,我希望文本“环绕”图像)。
如何使用 Google Script 将图像添加到 Google Doc,以便周围的文本环绕图像?
到目前为止我的脚本:
function myFunction(e) {
var t1 = 'Center for Success';
var t2 = 'Foundational Hall';
var t3 = 'Instruction Sheet for Testing Requirements';
var boldRight ={};
boldRight[DocumentApp.Attribute.BOLD]=true;
boldRight[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]=DocumentApp.HorizontalAlignment.RIGHT;
var boldCenterUnderline ={};
boldCenterUnderline[DocumentApp.Attribute.BOLD]=true;
boldCenterUnderline[DocumentApp.Attribute.UNDERLINE]=true;
boldCenterUnderline[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT]=DocumentApp.HorizontalAlignment.CENTER;
var filename = 'fileTest';
var doc = DocumentApp.create(filename);
var body = doc.getBody();
body.appendParagraph(t1).setAttributes(boldRight);
body.appendParagraph(t2).setAttributes(boldRight);
body.appendParagraph(space);
body.appendParagraph(t3).setAttributes(boldCenterUnderline);
doc.saveAndClose();
}
期望的结果:
我在这里看到可以通过多种方式添加图像,但是这两种方法都不适合我,而且我看不到如何控制包装属性。
更新
我尝试使用以下代码(在 URL 中显示了假 ID),但它只是创建了一个空白文档:
var image = "https://drive.google.com/open?id=2PJGK5C64HLKKoQIv52jGhUjjdiXU34Mp";
var fileID = image.match(/[\w\_\-]{25,}/).toString();
var blob = DriveApp.getFileById(fileID).getBlob();
body.appendImage(blob)
解决方案
推荐阅读
- javascript - Javascript 表单验证和阻止提交
- php - orders.php 页面的 wc_get_template 不起作用
- javascript - 让关键字在 ES5 上工作吗?
- java - 在 Java 中使用 SealedObjects 是否可以防止序列化漏洞?
- reactjs - 如何禁用自动完成材料-ui 演示的多行?
- nginx - 我已经删除了 Nginx 目录
- java - 如何从 s txt 文件中获取名称列表以显示在组合框中?
- php - PHP电子表格以无效格式保存文件
- c++ - 如何实现在向量中调用任何构造函数(如 emplace_back)的方法?
- javascript - 等待 JavaScript 中的动态文件加载