First of all, you should take a look at tika, which is written in Java, is free (licensed by Apache) and can convert all formats mentioned in the text. After that, the number of words should be trivial.
You can also use linux command line utilities to convert to text and write a simple wrapper around them.
(I cannot refer to them due to lack of reputation. Use Google Fu.)
- pdf: pdftotext (part of xpdf). see also question # 221359 on SuperUser.
- doc (x): abiword, catdoc, antiword, docxtotxt ... see also question 165978 about SuperUser.
- xls (and almost everything, but needs OpenOffice): unoconv
source share