微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用谷歌应用程序脚本打开受密码保护的 Excel 文件时出错

如何解决使用谷歌应用程序脚本打开受密码保护的 Excel 文件时出错

当前正在运行以下脚本以从 Gmail 复制 excel 附件。当文件不受密码保护时它工作正常,但当 excel 文件受密码保护时会引发以下错误

GoogleJsonResponseException: API call to drive.files.insert Failed with error: Bad Request

我找不到任何输入密码的功能。我预计此功能可能不存在。另一篇文章建议先触发 VBA 解密文件

问题:

  1. 驱动器 API 中是否存在密码功能
  2. 如何触发 VBA 脚本来解密文件。 (我不是在寻找 VBA 代码,只是 googlescript 触发器)
function getExcelFile(thread) 
{
  
  var label = GmailApp.getUserLabelByName("TO PROCESS");

  if(label != null){
    var threads = label.getThreads();
    for (var i=0; i<threads.length; i++) {
       
  //Steps to get the attachement
  var thread = GmailApp.getUserLabelByName("TO PROCESS").getThreads(0,1); //pulls all threads of all emails with tag
      var messages = thread[0].getMessages(); //pulls messages in first thread
  var len = messages.length; //Gets number of messages in first thread
  var message = messages[len-1] //get first message in given thread
  var attachments = message.getAttachments(); // Get attachment 
  
  //Steps to process the attachement
  var xlsxBlob = attachments[0]; // Is supposes that attachments[0] is the blob of xlsx file.
  var convertedSpreadsheetId = Drive.Files.insert({mimeType: MimeType.GOOGLE_SHEETS},xlsxBlob).id; //Converts Excel to "Google Sheet" in google drive and gets file Id
  var filename = xlsxBlob.getName(); //gets the converted files file name
  var tabName = filename.substring(13).slice(0,filename.length-18); // process the filename string into just the date to be Tab Name
  
  var sheet = SpreadsheetApp.openById(convertedSpreadsheetId).getSheets()[0]; // Location of converted Excel file -> Now google sheet
  var destination = SpreadsheetApp.openById("1e_pepsold-SHbndxcQ0pvdN9AGiZ31O5XcLFU8YfcwE"); //Location of Weekly schedule
  sheet.copyTo(destination); //copy the converted sheet into the working Weekly schedule sheet
  

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。