1

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?

Subaru Spirit
  • 394
  • 3
  • 19
  • I am not sure if Drive allows the network location connections, the only possible way to have the library or list of files is by utilizing Drive for Desktop, however it is very limited, have you review that option? – Ricardo Jose Velasquez Cruz Nov 14 '22 at 02:31
  • Unfortunately that is not an option as it's a legacy thing in my company to use that network drive... But no worries, if it's not possible, then it has to be done manually – Subaru Spirit Nov 14 '22 at 08:53

1 Answers1

1

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: