I
I
Igor2016-02-26 12:56:18
CMS
Igor, 2016-02-26 12:56:18

How to unload data from a form on a website into a .doc document?

Hello!
The essence of the task is as follows:
The site is supposed to have a form in which the user fills in the data (name, contract number, city, contact details, etc.). The site itself is under development (layout - bootstrap, cms wp).
There is also a .doc document template (statement) into which the data from the form should be uploaded.
How is this functionality implemented? Are there any implementation examples?
PS: I tried to describe the task in as much detail as possible, I hope that the question is not too general :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
V Sh., 2016-02-26
@JuniorNoobie

Good afternoon!
If MS Office is installed on the server, then the libraries for working with it (Excel.Interop, Word.Interop, etc.) are also installed.
The algorithm is as follows:
1) The form is filled on the client side and the data is sent to the server;
2) An instance of a Word document is created on the server, information from the template is entered into it and filled with data from the form;
3) The resulting Word file is NOT saved on the server, but is transmitted back to the client in a stream, in which, again, we indicate through what it should be opened on the client side.
If there is no MS Office on the server, then you can assemble it yourself, because. .docx is nothing more than a set of ordered xml files. You can open your template through the archiver and see for yourself, and if you dig into the insides of these files, you can find what data in xml you need to change.
Algorithm:
1) We receive data from the form;
2) We copy the template through the archiver (7zip, for example), open the necessary xml files and replace the information in them with the necessary one;
3) unload the file into the stream, remembering to destroy the modified copy of the template (well, or clear the memory if you haven't physically saved anything anywhere);
4) we transfer the stream to the client.

U
Uwe_Boll, 2016-02-26
@Uwe_Boll

Look Here

E
Evgeny Bukharev, 2016-02-26
@evgenybuckharev

Connect the PhpWord extension to the project, then place tags for replacement in the docx file, and change the tags to user data with the script, and then upload or save the finished document to the server.

K
Konstantin Nagibovich, 2016-02-26
@nki

Is MS Office installed on the server?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question