On Thu, 7 Apr 2011, Charles Gutjahr wrote:
My second need is for a simple way to specify column widths on a table
in an XWPF document. This is currently only possible by manipulating
underlying CTTc and CTTblGrid objects. It looks like someone briefly
considered it because there is some commented-out code
in XWPFTable.createEmptyTable() but a lot more work would need to be
done to get it working. The reason it's not straightforward is that
column widths are maintained in two places – CTTc and CTTblGrid – and
POI doesn't keep track of columns thus making it tricky to keep both
places in sync.
A lot of the code in XWPF has been user contributed, so works great in the
area that the user wanted, but doesn't always have a full picture design
behind it. So, finding things where two parts have to be kept in sync but
only one is updated isn't all that surprising :/
We generally rely on the next group of users to spot it and send in a
patch that fixes it :)
I need to be able to control the column widths in documents that my
application generates. So here is what I plan to add to POI and contribute as
a patch:
* Add a new class called XWPFTableCol which represents a column in a table.
It roughly maps to CTTblGridCol, so when document is loaded the XWPFTableCol
instances will be populated from CTTblGridBase.getGridColList()
Makes sense
* Add a list of XWPFTableCol to XWPFTable which tracks the columns being
used by the table
* Provide methods on XWPFTableCol to get, set and clear the width of the
column
Ditto
* Have a flag on those methods which defines whether a width change is
applied to individual rows, or just to the table grid (because Word allows
individual rows to have different column widths)
Oh joy... That one will probably need a unit test all to itself, and a
rather long java doc...
* Change XWPFTable.addNewCol() and XWPFTable.createRow() to use the list of
XWPFTableCol for column information instead of looking at the cells in the
first row. New rows will automatically copy column widths from each
XWPFTableCol to the appropriate XWPFTableCell in that row.
* Rename XWPFTable.addNewCol() to createCol() for consistency with
createRow()
* Add a XWPFTable.removeCol() method to remove columns
* Add methods to XWPFTableCell to get, set and clear the width of the cell.
All looks fine to me
Thanks!
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]