Put a = before text jump

妖精的绣舞 提交于 2020-12-13 04:49:05

问题


Hello I made this script to export the data from a column to a .txt on my google drive

function maquinasBonusHunt() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getActiveSheet();
  var range = sheet.getRange('G3:G' + sheet.getLastRow());
  var rows = range.getValues().filter(([g]) => g.toString() != "");
  var fileName="maquinas.txt";
  var folderName="Videos";
  var data = rows.splice(0);
  var str = data.map(function(e) {return e.join()}).join("\n");
  var separador = [" - ", " = "];
  var content = str;

  // get list of folders with matching name
  var folderList = DriveApp.getFoldersByName(folderName);  
  if (folderList.hasNext()) {
    // found matching folder
    var folder = folderList.next();

    // search for files with matching name
    var fileList = folder.getFilesByName(fileName);

    if (fileList.hasNext()) {
      // found matching file - append text
      var file = fileList.next();
      var combinedContent = content;
      file.setContent(combinedContent);
    }
    else {
      // file not found - create new
      folder.createFile(fileName, content);
    }
  }
}

Everything is fine but, I need to put a "=" before they jump to other text like y show you on the screenshot. https://i.stack.imgur.com/xvXDA.png


回答1:


I believe your goal as follows.

  • You want to add = to the last character of each row.

In order to achieve your goal, I would like to propose the following modification.

Pattern 1:

In this pattern, = is added when join is run.

From:

var str = data.map(function(e) {return e.join()}).join("\n");

To:

var str = data.map(function(e) {return e.join()}).join("=\n") + "=";

Pattern 2:

In this pattern, = is added after filter was used.

From:

var rows = range.getValues().filter(([g]) => g.toString() != "");

To:

var rows = range.getValues().filter(([g]) => g.toString() != "").map(([v]) => [v + "="]);

References:

  • join()
  • filter()
  • map()


来源:https://stackoverflow.com/questions/64841365/put-a-before-text-jump

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