You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2022/11/24 14:23:29 UTC
[Bug 66363] XWPFDocument.insertTable doesn't work at all
https://bz.apache.org/bugzilla/show_bug.cgi?id=66363
Nigel Gay <ni...@hotmail.ca> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--- Comment #1 from Nigel Gay <ni...@hotmail.ca> ---
The only workaround I can find is to create an XmlCursor for the insertion
point, then call XWPFDocument.insertNewTbl to create a throwaway table, then
use XWPFDocument.setTable to replace the throwaway table with the real one.
public XmlCursor newCursorForBodyElement (IBodyElement elem)
{
XmlCursor cursor;
if (elem instanceof XWPFParagraph)
{
XWPFParagraph para = (XWPFParagraph) elem;
cursor = para.getCTP ().newCursor ();
}
else if (elem instanceof XWPFTable)
{
XWPFTable table = (XWPFTable) elem;
cursor = table.getCTTbl ().newCursor ();
}
else
throw new RuntimeException ("Don't know how to create a cursor
from body element of type " + elem.getClass ());
return cursor;
}
.. and then can do ...
index = 3;
XWPFTable throwawayTable;
if (index < doc.getBodyElements ().size ())
{
// Insert before numbered element
XmlCursor insertionPoint = newCursorForBodyElement (doc.getBodyElements
().get (index));
throwawayTable = doc.insertNewTbl (insertionPoint);
}
else
{
// Insert at end
throwawayTable = doc.createTable ();
}
doc.setTable (doc.getTables ().indexOf (throwawayTable), dest);
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org