I am building a website application for a local charity, it is going well, I seem to overcome most challenges, but this is a huge problem I have, and I don't even know if it is possible.
I want the user to be able to click a button and output a Microsoft Word file by mail merging a text file and a prebuilt template (dotx) file, both on the server side. The text file will only contain one record that has been taken from an mySQL database and generated via PHP.
I know about using XSLT to modify the document file inside the document zip, but I do not have access to the php.ini on the charities server, and anyway it seems a little bit too much considering how simple it is to use create a Macro to Mail Merge.
So I am now thinking of using the Word Object Model, it would have to be via Javascript, but most of the users use either Firefox or Chrome, so would for eg. var oApplication = new ActiveXObject("Application.Word");
work with those browsers, or could I use simply = new Object("Application.Word");
?
Also can I confirm that the object in Javascript would then have the same function names and parameters as those in VBA, I have never tried using Word via Javascript, but if it's the same as VBA, then I should be fine.
I am using my localhost for development and the file structure is:
Where data.txt is the PHP generated CSV of the data taken from the database.
ActiveX/COM automation (which is required to access word.application
) is supported in IE only, no other browser supports it in any way.
If it were supported you would still not be able to easily interact with the Word files on the server from within the client.
You could generate the file on the server ( Generating word documents with PHP ) although to access functionality that's actually built into Word itself (like a mail merge) you would need to programmatically interact with a real instance of Word that's been installed on the server (using PHP/COM/word.application
) to control it, to avoid this, you would do whatever the mail merge does, manually.
Another alternative would be to have a Word document that contained VBA code that interacted with a PHP web service to generate the output document.