W
W
WebAnalytics12018-02-07 16:08:02
Google Apps Script
WebAnalytics1, 2018-02-07 16:08:02

Where is the error in the Google Script code for export to txt?

Hello,
There is a table
5a7af60826cde585990088.png
Task: export through (starting from 1) a column (starting from line 3) to a txt file (take the name from the first line). For this I wrote a script

function export() {
  var Folder = DriveApp.getFolderById("ID");
  var SpreadSheets = SpreadsheetApp.openById('ID').getSheetByName('Минуса');
  
  var values = SpreadSheets.getRange("A3:A").getValues();
  var txtName = SpreadSheets.getRange("A1").getValues();
  var text = values.map(function (a) {return a.join('\t');}).join('\r\n');
  var Files = Folder.getFiles();
  while(Files.hasNext()){
  var File = Files.next();
    if(File.getName() === txtName + ".txt"){
      Folder.removeFile(File);
    }
    }
  Folder.createFile(txtName + '.txt', text);

The problem arises if there are a lot of columns (the script becomes very long) and I tried to write in the form of a loop
function export() {
  var Folder = DriveApp.getFolderById("ID");
  var Files = Folder.getFiles();
  var SpreadSheets = SpreadsheetApp.openById('ID').getSheetByName('Минуса');
  var lastRow = SpreadSheets.getLastRow();
  var c =1;
  for(var i = 3; i<=lastRow;i++){
    for(;c<=15;c+2){
    var values = SpreadSheets.getRange(i, c).getValue();
    var text = values.map(function (a) {return a.join('\t');}).join('\r\n');}
      for(;c>15;c+2){var txtName = SpreadSheets.getRange(1, c).getValues();}
     while(Files.hasNext()){
  var File = Files.next();
    if(File.getName() === txtName + ".txt"){
      Folder.removeFile(File);}
     }
    Folder.createFile(txtName + '.txt', text);
    }
}

Writes
TypeError: Cannot find map function on avamys object

Please help me write this script correctly.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WebAnalytics1, 2018-02-08
@WebAnalytics1

https://ru.stackoverflow.com/a/782003/284316

A
Alexander Ivanov, 2018-02-08
@oshliaer

Replace
on the
But I wouldn't do that. The disk is a complex ecosystem of sensors and triggers. Perhaps you could dig a little deeper and understand the zen of the event model, maybe something will work more smoothly and smoothly, and really online.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question