I want to know if there is a way to know how many words in my document using my Google App Script ?
and if there is one
how can i make a trigger that will work when someone edit the file and if the number of words is bigger than the last number it would send an email to me
so far i was easily able to make the email function from my peovies work with it and the spreedsheet but for the Google Docs i have no idea how to do it ?
相关问题
- How can I force all files in a folder to be owned
- Google Apps Script: testing doPost() with cURL
- Google Apps Script to turn in, grade, and return a
- Script fails on SpreadsheetApp.openById - Requires
- Split Lines and Bold Text within a ui.alert Window
相关文章
- How to allow access for importrange function via a
- Google app script trigger not working
- Set Date/Time to 00:00:00
- indexOf returning -1 despite object being in the a
- How can my Google Apps Script be run by others the
- How to stop execution of Google Apps Script?
- Profiling the Performance of a Google App Script
- String starts with in Google Script
The easiest way must be using regular expressions.
I'm not an expert in this but I think the code below retrieves the number of words in a document
It works by adding a character ( I used \x07 ) before AND after each word.
This will increase the length of the string by two times the number of words.
You can see how it works at http://regex101.com/#javascript
You can add an onKeyUpHandler and perform the test in the handler.
I'm not going to show a full working code but I think the example linked below could help you to setup a very clean and elegant solution.
Google published a demo document a while ago called Cursor inspector (make a copy to use or read the original github) that has all the features you need except the word count function but that should be fairly simple to implement.
For example you could get all the text in a string and use
which will return the number of spaces, ie the number of words - 2 with a small approximation but the precision is not so important since the data is inspected only every 2 seconds (see below).
The idea is to poll the document every few seconds and from there do whatever you have to do, all this from the sidebar build with HTML Service and using JQUERY.
Did I mention it wasn't going to be easy game ?
Oh no! I'm afraid I forgot...
Anyway, have a "look and try" at this demo doc and make yourself an opinion.
I am not so sure about your requirement, But could you check whether this suits your need or not.