我已经搜索了这个网络,发现了许多解决方案"对于这个问题,似乎没有一个对我有用。
我的问题很简单。我想从一个可更改的源文件中导入信息....我认为一旦我克服了首先打开外部电子表格的实际问题,我就会舔这个。
我正在使用Google Apps脚本,并尝试使用单独的GoogleDoc电子表格在同一Google云端硬盘中打开文件。
据我所知,以下代码(一旦你拿出评论)应该打开一个电子表格文件但是会出现非法密钥错误。
function openafile() {
var files = DriveApp.getFiles();
while (files.hasNext()) {
var file = files.next();
// =//= look for a specific type of spreadsheet file (excel) - this will always be exported as this Mime Type
if ( file.getMimeType() == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) {
Logger.log('Attempting to open ' + file.getName());
// =//= none of these seem to work .... why?
// var ss = SpreadsheetApp.openById(file.getId());
// var ss = SpreadsheetApp.open(file);
// var ss = SpreadsheetApp.openByUrl(file.getUrl());
Logger.log('Success: ' + ss.getName());
}
}
}
答案 0 :(得分:1)
Gerardo已经回答了提出的实际问题,这导致了另一个问题......“好的,但我无法控制文件的原始格式。如何从Excel / CSV导入?”
https://stackoverflow.com/a/26858202/4941031
给出了这个后续问题的答案。