Hello everybody!
I am creating this post because dealing with a specific issue. Following is the context:
- I am using Aspose.Words for java
- I have a Word document which is my template
- On my website, I click on a button which action is to fill the template with Java objects and to generate the final Word document.
So here is the issue : in the Word template, I have a table that looks like this :
--------------------------------------------------------------------------------------
| Title 1 | Title 2 | Title 3 | Title 4 | Title 5 |
--------------------------------------------------------------------------------------
| | | | | |
| merged | merged | | | |
| cells | cells | -------------------------------------------------
| | | | | |
| | | | | |
--------------------------------------------------------------------------------------
What I’m trying to do is to browse through a Java table and to loop in order to fill the above Word table. For instance :
--------------------------------------------------------------------------------------
| Title 1 | Title 2 | Title 3 | Title 4 | Title 5 |
--------------------------------------------------------------------------------------
| | | | | |
| { MERGE | | | | |
| FIELD | | | | |
| TableSt | | -------------------------------------------------
| art:table } | | | | { MERGE |
| | | | | FIELD |
| | | | | TableEnd:|
| | | | | table } |
--------------------------------------------------------------------------------------
The expected result is a unique Word table with 1 header and as many rows as the size of the Java object “table”. For instance, for a size of 2, it should looks like this:
--------------------------------------------------------------------------------------
| Title 1 | Title 2 | Title 3 | Title 4 | Title 5 |
--------------------------------------------------------------------------------------
| | | | | |
| | | | | |
| | | -------------------------------------------------
| | | | | |
| | | | | |
--------------------------------------------------------------------------------------
| | | | | |
| | | | | |
| | | -------------------------------------------------
| | | | | |
| | | | | |
--------------------------------------------------------------------------------------
That doesn’t work. Not only the Word table doesn’t display as expected but the rest of the generated Word document becomes corrupted.
Did I put the { MERGEFIELD TableStart / End } at the wrong places ?
Can Aspose deal with table with merged cells ?
Is it a Word problem ?
Is there another way to achieve my goal ?
FYI, if we try with a simple table made of just 1 row, the following works:
--------------------------------------------------------------------------------------
| Title 1 | Title 2 | Title 3 | Title 4 | Title 5 |
--------------------------------------------------------------------------------------
| { MERGE | | | | { MERGE |
| FIELD | | | | FIELD |
| TableSt | | | | TableEnd: |
| art:table } | | | | table } |
--------------------------------------------------------------------------------------
This generates (let say “table” is a table of size 3):
--------------------------------------------------------------------------------------
| Title 1 | Title 2 | Title 3 | Title 4 | Title 5 |
--------------------------------------------------------------------------------------
| | | | | |
| | | | | |
--------------------------------------------------------------------------------------
| | | | | |
| | | | | |
--------------------------------------------------------------------------------------
| | | | | |
| | | | | |
--------------------------------------------------------------------------------------
Any idea or help would be much appreciated
Thank you! Do not hesitate if you need more details or examples.
Best regards,
Alex