Script for displaying word count in Google Spreadsheet

This is a very basic Google Apps Script that prints out the Word count of the Active Cell in Google Spreadsheet.

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ {name: “Word Count”, functionName: “getWordCount”}];
  ss.addMenu(“Custom”, menuEntries);

function getWordCount() {
  var activeCell=SpreadsheetApp.getActiveSpreadsheet().getActiveCell();
  var myValue = activeCell.getValue();
  var wCount = myValue.split(” “);
  Browser.msgBox(“Word Count is ” + wCount.length);

This has two functions onOpen and getWordCount, OnOpen adds a new menu to call the Word Count function and getWordCount actually does work of counting the number of words in the Active Cell.

The Result is printed out as a Message Box as shown below.

In Category: Technical

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.