1

I've scoured the interweb and found many many "solutions" to this problem, none of which seem to work for me.

My problem is a simple one. I want to import information from a changeable source file .... I think I have this licked once I get over the actual problem of opening the external spreadsheet in the first place.

I'm using Google Apps Script and am trying to open a file within the same Google Drive, from a separate GoogleDoc-spreadsheet.

The following code as far as I can see (once you take out the comments) should open a spreadsheet file but gives an illegal key error.

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());
    }
  }
}
A Martin
  • 21
  • 3
  • Do you see your 'Attempting to open ...' log entry? – Spencer Easton May 26 '15 at 16:33
  • 1
    You are trying to open a Microsoft Excel file. To use SpreadsheetApp you have to provide the ID of a Google Spreadsheet file. You can export the Excel file into Spreadhseet format and the use the ID of the new file in the SpredhseetApp.openById(). – Gerardo May 26 '15 at 17:39
  • Gerardo, you are a complete legend! I knew it would be something I was overlooking that would seem so obvious to someone else. Thank you for the /facepalm moment :) – A Martin May 27 '15 at 17:15

1 Answers1

1

Gerardo has kindly answered the actual question posed, which led on to another question ... "OK, but I have no control over the original format of the file. How do I import from Excel/CSV?"

https://stackoverflow.com/a/26858202/4941031

Gives the answer to this follow-up question.

Community
  • 1
  • 1
A Martin
  • 21
  • 3