I have been using docx4j to build database report based upon data retrieved from a database. I am trying to build a table with dynamic content from the database. Because every field has a different length, every column needs to have a custom length. I have not been able to find a way to accomplish this. I have managed to get the data in the table by changing the createTable() method to accept a two dimensional array of strings as a parameter. From this two dimensional array it then reads the row and column count and uses that to create the table. I use the method setValue() to insert the value into the right cell (still within the createTable() method). The columns adjust to the right size perfectly, however when there is a white space in the string the column will not adjust the width and place the second part on a new line within this row.
To illustrate I made the following example in a monospaced font:
- Code: Select all
What I want:
+-----------+----------------+-----+
|r1 c1 space|r1 c2 |r1 c3|
+-----------+----------------+-----+
|r2 c1 |r2 c2 otherspace|r2 c3|
+-----------+----------------+-----+
|r3 c1 |r3 c2 |r3 c3|
+-----------+----------------+-----+
- Code: Select all
what I get:
+-----+----------+--+
|r1 |r1 |r1|
|c1 |c2 |c3|
|space| | |
+-----+----------+--+
|r2 |r2 |r2|
|c1 |c2 |c3|
| |otherspace| |
+-----+----------+--+
|r3 |r3 |r3|
|c1 |c2 |c3|
+-----+----------+--+
Where of course the rX cY stands for (row X, Column Y).
Could you please assist me with this? As you might know from my previous post I am quite new to docx4j so if you could please explain me how to do this I would very much appreciate that.
Stijn