MS Word Object Model via Javascript: Mail Merge - javascript

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:
template\conformation.docx
template\data.txt
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.

Is a web-service an option for your application? If so, have a look at Docmosis - you can upload doc templates then send requests with data to do the mail merge outputting the result with various options including MS word.

Related

How to search inside excel file using HTML/JavaScript form

I have an excel file that contains around 3000 unique ids. I am creating a HTML form where the user will select a code from one of these ids. Similar to something where they click on the code field, which takes them to a new web page where they can either search a specific code or just select to show all and then manually select one code.
I am assuming that I need to use JavaScript or something similar over here to connect the excel file to the form, but I cannot find a specific answer to the question. I have seen a lot of websites like job application websites where they have you search for the university do something similar. But I am not sure where to begin. It would be great if someone pushed me into the right direction.
Javascript on the frontend (in a web browser) does not have access to the filesystem. You should use NodeJS (Javascript Runtime) which does run on the server side, and therefore has access to the filesystem.
Your specific issues can be solved with a simple HTTP GET or POST request to a small NodeJS server which will take the code as a query parameter and proceed according to the requirements you have.
I hope this helps.

How to retrieve file names from a specific directory using JavaScript or jQuery?

I want to make a code using only JavaScript or/and jQuery to access a static directory and retrieve the names of some icons i saved there (SVG icons) and display the names to the user. i couldn't do that with the file api and i have no idea where to start.
I'm going to assume from your mention of jQuery and the File API that you're trying to do this within a browser.
You can't. It just isn't allowed, there is no mechanism to provide it.
If you're in control of the machine where you want this information to be accessed, you can run a server process on it that can do that; code in the browser can then make a request to the server code to request the information. But there's no browser-only way to do it.

Extract file name with directory structure for internal web site

Environment:
html5
JavaScript
Angularjs
node.js
express.js
Couchbase
Question:
I understand the concerns and security measures implemented within the web environment to prevent the display of directory paths to the world. However, I have an issue that requires knowing the full directory path to a selected file.
I am building a web page for an internal website. The web page needs to allow the user to select a tab delimited file. This tab delimited file will exist on a network server, which is a policy instituted by the company and mandated by external auditors. This file may exist for various clients, with data specific to the client. With that said, the files will reside within different folder structures on the server(s). The user wants to pick the appropriate file and have the data uploaded to the database. Based on the size of the file (up to 10’s of millions of rows), the user does not want to wait for the web page to process immediately. Therefore, the solution is to create a task. The task will contain all the parameters necessary to manipulate the data prior to uploading the data to the database. I understand the simple solution is to upload the file to a common directory but that is not practical. As the user could set up several tasks that will upload the same tab delimited file to the database using different parameters.
I would like to have my task creation process contain the file name with the directory structure. When the background process executes the task, it can extract the data from the original location. Additionally, if I have multiple tasks extracting the same data, I not concerned I may have multiple copies of the data present.
I will appreciate any help with code snippets, website, etc. that may suggest methods to resolving this issue. Please not, that at the current moment, PHP is not an option. A management decision prevents the use of PHP.
TIA
Anthony
It is not exactly possible, so I see two solutions. One is to try and get the path to the temporary location of the file, rather than the actual permanent location.
Suppose your has an id of fileInput and you're using jQuery:
$('#fileInput').change( function(event) {
var tmppath = URL.createObjectURL(event.target.files[0]);
console.log("Temporary Path(Copy it and try pasting it in browser address bar):"
console.log(tmppath);
});
Otherwise I would just make a separate input for path, and show a brief instruction to users on how to copy-paste the URL from their Windows Explorer window.

Any way to save HTML Form data to database without webserver/sql?

So currently i'm buidling a local website within work.
one of the feature that needs to be built is a request submission form.
We originally had this email to a central mailbox but we want it to take the form data and save it to a database in this case Access.
Is there any possible way of doing this without using SQL or ASP ? As the website is being build on a local server for all members of staff to access.
In the end all I want to do is create a form the user can submit which is sent to a database. Is it possible or would it be better to stick with the email idea?
It is not possible to save data without a database server. Only thing can be done is cookies in javascript but these will not be available always and will never help you cause..
First of all I would like to say that html/css is client side scripting language, without using server side language you can't save anything. You can use php or javascript(ajax) in order to do that.
Unless you are targeting Safari browsers, you can try using IndexedDB(http://caniuse.com/#feat=indexeddb), a form of local storage supported by major browsers, with no size limit. It can be used carefully to emulate a remote database using a JavaScript object relational mapper.
I strongly suggest you a server :). If you don't want to use sql there are many ways to save data. The simplest would be to write a file on disk with what you need.
Only under Internet Explorer, you can save data into MS Access database for example using ActiveX. But html file must be open locally.
Edit:
If needed I can write you a sample code.

I need to generate a JSON file in browser using (currently) javascript

I have a website that allows users to select a date range from a data set. At least, that's the goal.
What I would like to have happen: the user selects a date range, presses the submit button, and a script generates a JSON file which MATLAB reads to generate the graphs.
Any thoughts on resources to help accomplish this?
You'll need the script that fires off to be server side. JavaScript is client side and can not, in any way, access, modify, or otherwise create files on the client. You'll have to use a language like PHP to create the file.
Example using PHP:
Once the file is created, force a request on the client side to fire asking for the file. Set the PHP header to Content-Disposition: attachment; filename="< Place file name here>".
This will prompt the browser to launch a download prompt allowing the user to download the file.
Hope this helps.
You can use Downloadify, a small Flash component with a Javascript interface that allows you to create files on the client that a user can download. That's what I used in a similar situation.
You could also try and use Data URI but they are a quite limited and browser specific so some issues may arise.
These may be alternative solutions to the previous answer that suggested using server side code to generate the file.

Categories