📜 ⬆️ ⬇️

Generation of documents. Easy and free

Continuing the theme of generating documents on the basis of templates, I want to discuss the creation of a document in which, in addition to relatively permanent parts, there are parts whose form and content depend entirely on the data. Those. we are not talking about the trivial filling of fields or simple tables. We are talking about tables with different textures, with different numbers of columns under one header, and the very look of the table is determined by the data.

To implement such a document in a template, you can pre-define individual possible rows of a table, give them a name, and then assemble a table from these lines just as the beads are put on a thread, like threads are stacked layer by layer into the fabric with the desired pattern.
In the process of generating these auxiliary lines are removed from the document. Which line should be inserted into the document is determined by its name. The named string does not have to be a row of the table, it can be text with the necessary display attributes.

Thus it is possible to assemble a document where text alternates with various tables. In addition to the named strings, the template specifies the place from where line-by-line printing starts. The task of the programmer in this case is reduced to the formation of XML, which, in addition to the data, will indicate which string to display them. So almost complete (only the name of the string specifies the format) is achieved separation of data from their presentation. And what is nice, the row names can be meaningful, and generation occurs quickly.
')
In conclusion, I want to add that there may be several places in the template where you need to type data lines. Each place has its own name (id). In XML with input data, it is necessary to transfer this name to a certain tag before typing data line by line. Naturally, the print data must be sorted in the order of the rows.

Source: https://habr.com/ru/post/336574/


All Articles