我们可以动态更改Google文档中的图片吗?

问题描述 投票:0回答:2

我正在使用Google App Script编写合同应用程序。

它从包含卖方签名和姓名缩写的图像的模板中创建GoogleDoc。

由于有五个卖方,并且有十二个不同的模板,有没有办法改变签名和缩写的图像?

我不知道从哪里开始寻找。

谢谢,祝你有美好的一天!

  • Eric

编辑:我在DocumentApp中发现了有关InlineImage的东西...仍在寻找中

google-apps-script google-docs google-docs-api
2个回答
0
投票

以下是一些小代码,可在Google文档中添加图片。希望这会给您Idea带来帮助。我曾经使用类似的概念制作了一个resume builder应用程序,该应用程序替换了个人资料图片和签名图片

//Make a UI form to upload Image
function doGet() {
  var app = UiApp.createApplication();

  //Form
  var form = app.createFormPanel().setEncoding('multipart/form-data').setId('form');
  //Add this form to the application
  app.add(form);

  //Panel to hold form elements
  var panel = app.createVerticalPanel();
  //add this panel inside form
  form.add(panel);

  //Now create form elemnts
  var label1 = app.createLabel('Upload Image');
  var uploadControl = app.createFileUpload().setName('file').setId('file');
  var submitBtn = app.createSubmitButton('Submit');
  //Add all these elemnts to the panel
  panel.add(label1).add(uploadControl).add(submitBtn);

  //Return the application to the service URL
  return app;
}

//This function is callend when the form is submitted
function doPost(e){
  var fileBlob = e.parameter.file; //This is the image blob if an image is uploded

  //Open the document
  var doc = DocumentApp.openById('ID OF GOOGLE DOC')//change Id of the document
  //get the body of document
  var docBody = doc.getActiveSection();
  //Append the iamge in document body
  docBody.appendImage(fileBlob);
  //Save and close the document
  doc.saveAndClose();
}

0
投票

可用于使用URL引用图像和窗台问题,但如何将此脚本附加到GoogleDocs文件中

© www.soinside.com 2019 - 2024. All rights reserved.