Skip to content

Instantly share code, notes, and snippets.

@nabinno
Created August 31, 2014 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nabinno/efb58f5023a49c434ef4 to your computer and use it in GitHub Desktop.
Save nabinno/efb58f5023a49c434ef4 to your computer and use it in GitHub Desktop.
google apps script of deleting newline for google spreadsheets
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function deleteNewline() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var numColumns = rows.getNumColumns();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
for (var j = 0; j <= numColumns - 1; j++) {
var row = values[i][j];
var row2 = row.replace(/\n/g,"");
var cell = sheet.getRange(i+1,j+1);
cell.setValue(row2);
}
}
};
/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
* for invoking the readRows() function specified above.
* The onOpen() function, when defined, is automatically invoked whenever the
* spreadsheet is opened.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Delete Newline",
functionName : "deleteNewline"
}];
spreadsheet.addMenu("Script Center Menu", entries);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment