问题
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