I'm not sure - maybe the Open Office Java libraries support manipulating the documents directly? If not there may be other open-source libraries available that can do this.
In Alfresco 1.4 the JavaScript API can execute repository "actions". This means you could write a custom Java action making use of the appropriate library, add it to the repository and then call it from Alfresco JavaScript.
Thanks,
Kevin