How To Download / Export Sheets In Spreadheet Via Google Apps Script

前端 未结 4 1731
故里飘歌
故里飘歌 2021-01-01 07:46

The task is to automate the manual process accomplished by the menu option \"File | Download As | Plain Text\"

I want to be able to control the saved file name, whic

4条回答
  •  爱一瞬间的悲伤
    2021-01-01 08:05

    I have exported a spreadsheet as CSV directly into a local hard drive as follows:

    1. Get the CSV content from current sheet using a variation of function convertRangeToCsvFile_() from the tutorial on this page https://developers.google.com/apps-script/articles/docslist_tutorial#section3

      var csvFile = convertRangeToCsvFile_(...);
      
    2. Then select a drive folder that is syncing to a local computer using Drive

      var localFolder = DocsList.getFolderById("055G...GM");
      
    3. And finally save the CSV file into the "local" folder

      localFolder.createFile("sample.csv", csvFile);
      

    That's it.

提交回复
热议问题