You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Mark Beardsley <ma...@tiscali.co.uk> on 2010/12/17 16:56:27 UTC

Re: XWPF: Need a table wie 2 merged cells at the first row

Not sure that is the best way to do what you are after and I have no idea if
this will work as an alternative but you could give it a go. I think that
the best approach to adopt is one where the table is built row by row and
each row is assembled cell by cell. That it to say that you create the
table, add a row to it and then a cell to that row. Next, add a new row to
the table and this time add two cells to that row; I am hoping that the
single cell in the first row will simply span the whole width of the table.
The code might look something like this but do bear in mind please that I
have not tested this code so cannot say for certain if it will work. Either
way, I think it gives you an idea of the solution and should allow you to
progress it further.

// To build the header row spanning two columns.
XWPFTable table = document.createTable();
XWPFRow row = table.createRow();
XWPFTableCell cell = row.createCell();
XWPFParagraph para = cell.addParagraph();
para.createRun().setText("Hopefully merged.");
// May need to call this method, not sure
table.addRow(row);

// Now to build subsequesnt rows each containing two cells.
row = table.createRow();
cell = row.createCell();
// And set the rcell contents here before adding a new cell to the end of
the row.
cell = row.addNewTableCell();
..etc

I do not know if this will work - and admit that I have not tested it out
yet - but think that it ought to do so.

Good luck.

Yours

Mark B

-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/XWPF-Need-a-table-wie-2-merged-cells-at-the-first-row-tp3306023p3309604.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: XWPF: Need a table wie 2 merged cells at the first row

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Ignore that, it will not work and the results resemble those you already
have.

Digging around though, I found that it is possible to 'add' and instance of
an XWPFTable into an XWPFCell. So, my new idea is to create a table with
just two rows and a single cell on each row. Into the cell on the first row
you would add text and into the cell on the second, another XWPFTable.

As I type, I have not yet cracked the problem of creating an instance of the
XWPFTable class - that is NOT using the documents createTable() method but
using something like new XWPFTable(). The arguments that I have to supply to
the constructor are still less than clear as I type this and I do not know
if I will have the chance to look again this side of Christmas but maybe you
can.

Yours

Mark B


-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/XWPF-Need-a-table-wie-2-merged-cells-at-the-first-row-tp3306023p3312309.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org