final short expectedCellsCount = _tprops.getItcMac();
int lastCellStart = 0;
- List<TableCell> cells = new ArrayList<TableCell>( expectedCellsCount );
- for ( int p = 0; p < (endIdxExclusive - startIdxInclusive); p++ )
+ List<TableCell> cells = new ArrayList<TableCell>(
+ expectedCellsCount + 1 );
+ for ( int p = 0; p < ( endIdxExclusive - startIdxInclusive ); p++ )
{
Paragraph paragraph = getParagraph( p );
String s = paragraph.text();
- if ( s.length() > 0
- && s.charAt( s.length() - 1 ) == TABLE_CELL_MARK
+ if ( ( ( s.length() > 0 && s.charAt( s.length() - 1 ) == TABLE_CELL_MARK ) || paragraph
+ .isEmbeddedCellMark() )
&& paragraph.getTableLevel() == levelNum )
{
TableCellDescriptor tableCellDescriptor = _tprops.getRgtc() != null
}
}
- if ( lastCellStart < (endIdxExclusive - startIdxInclusive - 1) )
+ if ( lastCellStart < ( endIdxExclusive - startIdxInclusive - 1 ) )
{
TableCellDescriptor tableCellDescriptor = _tprops.getRgtc() != null
&& _tprops.getRgtc().length > cells.size() ? _tprops
.getRgdxaCenter()[cells.size() + 1] : 0;
TableCell tableCell = new TableCell( lastCellStart,
- (endIdxExclusive - startIdxInclusive - 1), this, levelNum,
- tableCellDescriptor, leftEdge, rightEdge - leftEdge );
+ ( endIdxExclusive - startIdxInclusive - 1 ), this,
+ levelNum, tableCellDescriptor, leftEdge, rightEdge
+ - leftEdge );
cells.add( tableCell );
}
+ TableCell lastCell = cells.get( cells.size() - 1 );
+ if ( lastCell.numParagraphs() == 1
+ && ( lastCell.getParagraph( 0 ).isTableRowEnd() ) )
+ {
+ // remove "fake" cell
+ cells.remove( cells.size() - 1 );
+ }
+
if ( cells.size() != expectedCellsCount )
{
logger.log( POILogger.WARN,
public void setCantSplit( boolean cantSplit )
{
_tprops.setFCantSplit( cantSplit );
- _papx.updateSprm( SPRM_FCANTSPLIT, (byte) (cantSplit ? 1 : 0) );
+ _papx.updateSprm( SPRM_FCANTSPLIT, (byte) ( cantSplit ? 1 : 0 ) );
}
public boolean isTableHeader()
public void setTableHeader( boolean tableHeader )
{
_tprops.setFTableHeader( tableHeader );
- _papx.updateSprm( SPRM_FTABLEHEADER, (byte) (tableHeader ? 1 : 0) );
+ _papx.updateSprm( SPRM_FTABLEHEADER, (byte) ( tableHeader ? 1 : 0 ) );
}
public int numCells()
--- /dev/null
+package org.apache.poi.hwpf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hwpf.HWPFDocument;
+
+public class TestTableRow extends TestCase
+{
+ public void testInnerTableCellsDetection() throws Exception
+ {
+ HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
+ .getDocumentInstance().openResourceAsStream( "innertable.doc" ) );
+ hwpfDocument.getRange();
+
+ Range documentRange = hwpfDocument.getRange();
+ Paragraph startOfInnerTable = documentRange.getParagraph( 6 );
+
+ Table innerTable = documentRange.getTable( startOfInnerTable );
+ assertEquals( 2, innerTable.numRows() );
+
+ TableRow tableRow = innerTable.getRow( 0 );
+ assertEquals( 2, tableRow.numCells() );
+ }
+
+ public void testOuterTableCellsDetection() throws Exception
+ {
+ HWPFDocument hwpfDocument = new HWPFDocument( POIDataSamples
+ .getDocumentInstance().openResourceAsStream( "innertable.doc" ) );
+ hwpfDocument.getRange();
+
+ Range documentRange = hwpfDocument.getRange();
+ Paragraph startOfOuterTable = documentRange.getParagraph( 0 );
+
+ Table outerTable = documentRange.getTable( startOfOuterTable );
+ assertEquals( 3, outerTable.numRows() );
+
+ assertEquals( 3, outerTable.getRow( 0 ).numCells() );
+ assertEquals( 3, outerTable.getRow( 1 ).numCells() );
+ assertEquals( 3, outerTable.getRow( 2 ).numCells() );
+ }
+
+}