csvgoogle-apps-scriptnetwork-drive

How to export google sheet to CSV and store the CSV in a Network Drive (NOT the shared drive in google drive)?


In this post, I can use the script to export a sheet from google sheet to a csv file, but that file is saved in my google drive. How can I export it to a network drive? The network drive I mean is that when you open file explorer, and you can search \\Location1\location2\location3 to get to the network drive.

Here is a link to a simple google sheet with the appscript that can export it to a csv file. Here is the script (you can access it in the file as well):

function sheetToCsv()
{
    var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
    var sheet_Name = "Sheet1"
  
  
    var requestData = {"method": "GET", "headers":{"Authorization":"Bearer "+ScriptApp.getOAuthToken()}};
  
      var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_Name)
      var sheetNameId = sheet.getSheetId().toString();
  
      params= ssID+"/export?gid="+sheetNameId +"&format=csv"
      var url = "https://docs.google.com/spreadsheets/d/"+ params
      var result = UrlFetchApp.fetch(url, requestData);  
  
   var resource = {
  title: sheet_Name+".csv",
  mimeType: "MimeType.csv"
     }
   var fileJson = Drive.Files.insert(resource,result)
  
} 

How to adapt the code to store the csv file in network location \\Location1\location2\location3?


Solution

  • Google Drive with Network Drives

    For future references for the community: After reviewing the documentation and the Drive V3 API capabilities, as suggested in my comments. The best alternative to have a network drive available over the file explorer in Windows is by utilizing the official Drive for Desktop application or utilizing third party options. This is because it creates a partial Drive over windows so it is accessible and locally streaming:

    enter image description here

    It has also been discussed over other communities and suggested a similar scenario and workaround to use Drive for Desktop, however, it is very limited when it comes to connecting or integration with external API's or App Script like in this case.

    It would be an excellent idea to make a feature request or provide insight about this limitation on Drive, similar to the discussions being done over the other communities:

    References: