Convert any xls-xlsm files to Google Sheet format and overwrite the oldest existing GS file with that name

时间秒杀一切 提交于 2019-12-11 15:19:33

问题


I decided to open this topic because there is very little material in this regard and in my opinion many are asking the same question. I'm trying to write an script to convert an .xls or a .xlsm file stored on Google Drive to a Google Sheets file. I'm not interested in converting macros inside the .xlsm file, only converting the base file. This script should be able to overwrite the oldest file with the new one if it has the same name.

The topics in which I found more material are these:

  1. How to automatically import data from uploaded CSV or XLS file into Google Sheets
  2. Converting .xls to google spreadsheet in google apps script
  3. Convert all xls files available in a folder into "Google Doc Spreadsheets"?

these topic links inserted above are partial and in any case they do not allow the conversion of the .xlsm format.

I started from this code (taken from here), but I don't know how to modify it to make it convert both the .xls and .xlsm files and let them overwrite them if they are already in Google Drive

/**
* Sample use of convertExcel2Sheets() for testing
**/
function testConvertExcel2Sheets() {
  var xlsId = "0B9**************OFE"; // ID of Excel file to convert
  var xlsFile = DriveApp.getFileById(xlsId); // File instance of Excel file
  var xlsBlob = xlsFile.getBlob(); // Blob source of Excel file for conversion
  var xlsFilename = xlsFile.getName(); // File name to give to converted file; defaults to same as source file
  var destFolders = []; // array of IDs of Drive folders to put converted file in; empty array = root folder
  var ss = convertExcel2Sheets(xlsBlob, xlsFilename, destFolders);
}

I would like to thank anyone who decided to help me and therefore to give all those who are asking the same question.

来源:https://stackoverflow.com/questions/49841697/convert-any-xls-xlsm-files-to-google-sheet-format-and-overwrite-the-oldest-exist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!