excel - Error Opening password protected excel file with google app script
问题描述
Currently running the below script to Copy an excel attachment from Gmail. It works fine when the file isn't password protected but throws the following error when the excel file is password protected.
GoogleJsonResponseException: API call to drive.files.insert failed with error: Bad Request
I can't find any functionality to enter a password. I expect this feature may not exist. Another post suggested triggering VBA to decrypt the file first.
Question:
- Does the password functionality exist in the drive API
- How can I trigger a VBA script to decrypt to file. (i'm not looking for the VBA code just the googlescript trigger)
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
解决方案
推荐阅读
- javascript - json提取后出现错误“无法读取未定义的属性'map'”
- python - 具有多个元素的数组的真值是不明确的。使用 a.any() 或 a.all()。WHILE 绘制 3d 图形
- docker - JFrog Artifactory 错误:将具有清单 v2 模式 1 的 Docker 映像推送到此存储库被阻止
- pyomo - Pyomo - 添加/删除决策变量
- python - 使用python并排查看仪表板
- python - 在处理缺少工作表的文件时从多个 Excel 文件中连接单个工作表
- reactjs - React.js 中的“动态”路径
- android - Flutter - Android 应用程序只显示一个空白屏幕
- django - 永久超级用户 Django Docker
- mysql - 为父表选择子表的值数