--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/e9896a46-de77-4512-92e8-dcac83969df2n%40googlegroups.com.
Ed is correct. That function is where you need to improve speed. It seems to grab all data in sheet once and place it in Data, then it starts poking the same sheet one cell at a time inside your row/col for loops.
Here is what I propose you do:
Changes in function are below. You will see where I commented out some of your statements just so you can follow the changes needed. Feel free to delete these statements once you understand what it is doing.
I do not know if function works or not, was just looking at efficiency.
function convertToTSV()
{
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheets = ss.getSheets();
var folderId = GetFolderId(ss.getName());
var folder = DriveApp.getFolderById(folderId);
for (var s in sheets)
{
var tsv = "";
var data = sheets[s].getDataRange().getValues();
var sheet = sheets[s];
var cols = sheet.getLastColumn() + 1;
var rows = sheet.getLastRow() + 1;
Logger.log('ss:' + sheets[s].getName());
//for (d in data) {
var cumulative = "";
for (var row = 1; row < rows; row++) {
for (var col = 1; col < cols; col++) {
//var altData = sheet.getRange(row, col);
var cellDataValues = data[row-1][col-1]; //altData.getValues();
var cellCumulative = "";
for (var curAltValue in cellDataValues) {
cellCumulative += cellDataValues[curAltValue];
if (curAltValue != cellDataValues.length - 1) {
cellCumulative += ' ';
}
}
while (cellCumulative.indexOf('\n') > -1) {
cellCumulative = cellCumulative.replace('\n', ' ');
}
cumulative += cellCumulative;
if (col != cols - 1) {
cumulative += '\t';
}
}
cumulative += '\n';
//Logger.log('cumulative:'+cumulative);
}
tsv = cumulative;
//}
folder.createFile(sheets[s].getName() + ".tsv", tsv);
}
Browser.msgBox('Files are waiting in a folder named ' + folder.getName());
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAANZsGMMbiNR%2BfgwH%2Bx%3DcyNMVkzBq8F7VgfT76MyNJn3rH4f-g%40mail.gmail.com.