Creating Spreadsheet from Excel file

These scripts can be executed on Script Editor. But, in order to use these, you have to enable Drive API of Advanced Google services and of Google API Console. “Drive API v2” can be used at Google Apps Script by enabling Drive API of Advanced Google services and of Google API Console.

How to use it is as follows.

  1. In the script editor, select Resources > Advanced Google services

  2. In the dialog that appears, click the on/off switch for Drive API v2.

  3. At the bottom of the dialog, click the link for the Google API Console.

  4. In the console, click into the filter box and type part of the name of the API “Drive API”, then click the name once you see it.

  5. On the next screen, click Enable API.

  6. Close the Developers Console and return to the script editor. Click OK in the dialog. The advanced service you enabled is now available in autocomplete.

The detail information is https://developers.google.com/apps-script/guides/services/advanced.

1. Creating Spreadsheet from Excel file on Google Drive

var fileID = "#####";
var folderID = "#####";
var filename = "filename";

var res = Drive.Files.insert({
  "mimeType": "application/vnd.google-apps.spreadsheet",
  "parents": [{id: folderID}],
  "title": filename
}, DriveApp.getFileById(fileID).getBlob());

2. Creating Spreadsheet from Excel file on Web Site

var fileURL = "https://#####/sample.xlsx";
var folderID = "#####";
var filename = "filename";

var res = Drive.Files.insert({
  "mimeType": "application/vnd.google-apps.spreadsheet",
  "parents": [{id: folderID}],
  "title": filename
}, UrlFetchApp.fetch(fileURL).getBlob());

For example, when you want to retrieve created file ID, you can retrieve it by

res.id

 Share!