Created
April 8, 2017 23:51
-
-
Save ashblue/0d35c1730f14a924cff093cf3ee0e220 to your computer and use it in GitHub Desktop.
Google script for counting words in cell ranges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onOpen() { | |
var menu = [{name: 'Count Words', functionName: 'countWords'}]; | |
SpreadsheetApp.getActive().addMenu('Count', menu); | |
} | |
function countWords() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var data = sheet.getActiveRange().getValues(); | |
var s = ""; | |
for (var i in data) { | |
for (var j in data[i]) { | |
var v = data[i][j]; | |
s += v + " "; | |
} | |
} | |
s = s.trim(); | |
var sa = s.split(" "); | |
var sCount = sa.length; | |
Logger.log(sa); | |
Logger.log(sCount); | |
sheet.appendRow(['Word Count', sCount]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment