I have an .xls file stored in Google Drive. I want to convert it to the Google Sheets spreadsheet file format from Google Apps Script. Is there any way to do this without external solutions?
4 Answers
This is now possible using the Advanced Drive service:
https://developers.google.com/apps-script/advanced/drive
When using Drive.Files.insert, simply set the optional parameter "convert" to "true".
var file = {
title: 'Converted Spreadsheet'
};
file = Drive.Files.insert(file, xlsxBlob, {
convert: true
});
This was also obtained from the above given issue

- 7,417
- 6
- 40
- 55
-
Yep, already using it for a few years. Just forgot to update info here. – Buravchik Feb 24 '16 at 13:52
-
3You can also set the destination folder by providing the "parents" parameter to Drive.Files.insert. Like so: `parents: [{"kind": "drive#parentReference", "id": "folder id"}]` – Ben Visness Apr 01 '16 at 18:19
-
I'm getting "empty response". Any ideas? – kurokirasama Jun 01 '17 at 23:39
-
To enable 'Drive' service, open Google Apps Script console, click on + icon next to Services and select 'Drive API'. – aareeph Apr 01 '22 at 05:49
Other than using the delivered 'upload' and convert functions, it's not currently available. Requesting enhancement request here: http://code.google.com/p/google-apps-script-issues/issues/detail?id=1019

- 910
- 6
- 13

- 168
- 12
-
This answer is outdated since Google now provides the Advanced Drive Service. See Hameed's answer. – Ben Visness Apr 01 '16 at 18:15
Here's the complete code to create a file in a particular folder: (was a hint but was not completely apparent to me from @ben-visness comment)
var file = {
"title": filename,
"parents": [{"id": folderId}]
};
file = Drive.Files.insert(file, blobObj, {
"convert": true
});
Note: This will require enabling advanced Drive service from within Google Apps Script - Menu > Resources > Advanced Google Services AND Menu > Resources > Advanced Google Services > Google API Console.

- 51
- 5
Here's the code I used to convert an Excel file into a Google Sheets file, with the same name and in the same folder.
var excel = DriveApp.getFileById(...);
var resource = {
title : excel.getName(),
mimeType : MimeType.GOOGLE_SHEETS,
parents: [{id : folder.getId()}],
}
Drive.Files.insert(resource, excel.getBlob());
In my case, I already had a folder
object available which represented the folder I wanted to save the sheet to, but you could just as easily get the folder of the original file using excel.getParents()
.
You will also have to enable an Advanced Google Service called "Drive API" in order to use Drive.Files
. Read more here.
Solution was originally derived from this article.

- 101
- 1
- 7