问题描述
当前正在运行以下脚本以从 Gmail 复制 excel 附件。当文件不受密码保护时它工作正常,但当 excel 文件受密码保护时会引发以下错误。
GoogleJsonResponseException: API call to drive.files.insert Failed with error: Bad Request
我找不到任何输入密码的功能。我预计此功能可能不存在。另一篇文章建议先触发 VBA 解密文件。
问题:
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 (将#修改为@)