Automatically insert odt wordcount into a Calc cell?

Is it possible to automatically insert the wordcount of an odt or txt file into a Calc cell?

I havent found anything on it, but I’d like to be able to edit a bunch of different text files, and then use Calc to autoscan those files to get their individual wordcounts. Then I would sum up all the words in the cells in calc.

It’s not hard to do the final summation, but I dont know of any way to get the wordcounts from the odt or txt files.

Maybe via a macro or something?

What’s your mental concept of “or something”?

Of course, the file(s) must be opened.
You need to identify the file(s) by correct full pathname(s).
This may be done with the help of string formulas. Finally you have a full pathname in one cell and can use it as the parameter value for the following user function which you call from a (best adjacent) different cell.

Function wordCountExternalFile(pFileIdentifyer As String)
REM Full absolute pathname required here.
wordCountExternalFile = 0
On Local Error Goto finally
theUrl = ConvertToURL(pFileIdentifyer)
If NOt FileExists(theUrl) Then Exit Function
Dim args(0) As New com.sun.star.beans.PropertyValue
args(0).Name = "Hidden"
args(0).Value = True
docExt = StarDesktop.loadComponentFromURL(theUrl, "_blank", 0, args)
wordCountExternalFile = docExt.WordCount
finally:
On Local Error Goto finished
docExt.Close(True)
finished:
End Function  

This can only work for files for which a WordCount property is created. Plain text files with the extension .txt will do …