poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Beardsley <markbrd...@tiscali.co.uk>
Subject Re: Replacing placeholder to a Table.
Date Tue, 22 Feb 2011 17:15:07 GMT

If I remember correctly, the correct way to do this is to use the
createTable() method of the XWPFDocument object. The only drwaback with this
is that I cannot see any way to position the table within the document. Have
you looked at using the insertTable(int XWPFTable) method yet. That promises
to allow you to position the table within the document although I am not
clear exactly how it works and you would need to experiement with various
different values for the first parameter just to see how that works. I am
guessing that you are able to position the table between paragraphs but I do
not know this for a fact, sorry. From the top of my head, I think you will
need to do something like this;

XWPFDocument document = new XWPFDocument(new FileInputStream(new

// Create the tbale object and then populate it
XWPFTable table = document.createTable(3, 4);

// Insert it nto the document
document.insertTable(2, table);

just what value you pass as the first parameter, I do not yet know but
suspect it to be the number of paragraphs that should precede the table in
the document but I cannot promise that this is the case at all.

Sadly, I will not have the time to play with any code for a day or so -
vandals, do not get me started on that problem, but I will try as soon as I
have some time. It may well be that what you want is beyond the capabilities
of the api as it currently stands but I do hope not. If that is the case,
you may want to consider working with the developers to create a patch that
supports the required functionality and then commit this to the project. The
final, fallback position, would be to unzip the document, work directly on
the raw xml and then zip it all up again. Not my preferred option by any
means but it might get you working quickly if time is pressing and the
project deadline is looming.


Mark B
View this message in context: http://apache-poi.1045710.n5.nabble.com/Replacing-placeholder-to-a-Table-tp3392424p3395841.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

View raw message