smartinmedia / Net-Core-DocX-HTML-To-PDF-Converter

.NET Core library to create custom reports based on Word docx or HTML documents and convert to PDF
MIT License
322 stars 76 forks source link

Docx templates allow to put multiple placeholders in one cell #5

Closed Mastard69 closed 4 years ago

Mastard69 commented 4 years ago

I made a little change in the DocX handler, that allows to put multiple placeholders in one cell (that is for table placeholders obviously). I have to generate a résumé in my project, and for display reason, 1 cell = 1 placeholder does not work for me. Example with work experiences section, I'd want:

==StartDate== - ==EndDate== ==Company== : ==Role==

It's impossible with 1 cell = 1 placeholder because it's on 2 lines, And for layout reason, it would not be very fancy to place each placeholder in its own cell.

So now, a cell can contain multiple placeholders. I also had to change the way it searches for a table (== becomes Contains) because if the placeholder used to search the table is in a cell with other placeholders, it won't match.

Previous behaviour is not changed at all.

Finally, I added a classic .gitignore (provided by github) to the solution, in order to avoid all the useless files generated by Visual Studio.

Hope it's ok for you. Thanks for your work !

Mastard69 commented 4 years ago

I also modified the code in order to allow Text and Table placeholders in headers and footers. I tried to do the same for Image placeholders, without success (The output file is not able to display the image in a header/footer if I just search for placeholders in them). Surely, inserting images in headers/footers needs different code than inserting in the document's body, but I don't have enough OpenXML knowledge at the moment to make it work

Finally, it is now also possible to have the same table placeholders multiple times in the document.

Mastard69 commented 4 years ago

New little change. I noticed that an error was thrown if the value of a text placeholder is null. I fixed it and replace it by an empty string as value. Also, in my use case, I have documents with tables that don't contain all the placeholders. Before, the code searched in the document with the first key of a TablePlaceholder. I changed this behaviour in order to find any key of the TablePlaceholder in a table row.

Again, no breaking change here.