poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Gutjahr <org.apache....@charlesgutjahr.com>
Subject Proposed table column width patch for XWPF
Date Thu, 07 Apr 2011 13:53:33 GMT

In my last email I mentioned that I need two things in POI that aren't currently supported,
so I propose to implement them and provide patchs. See my last email about my first need,
for revision identifiers.

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.

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()
 * 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
 * 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
 * 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.

Does anyone have any comments on or objections to this plan?

Note also that I suspect the current table code creates documents that cause Apple iWorks
Pages '09 and OS X Quick Look to crash. I suspect it is the lack of a CTTblGrid in tables
created by POI, an element that is standard in tables created by Word or Pages. I'll investigate
that when I work on this patch, and if this really the cause of crashes then I'll raise a
bugzilla bug then fix it :-)

  • Unnamed multipart/alternative (inline, None, 0 bytes)
    • Unnamed multipart/related (inline, None, 0 bytes)
View raw message