git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1720035 13f79535-47bb-0310-9956-ffa450edef68tags/REL_3_14_BETA1_RC2
S extends Shape<S,P>, | S extends Shape<S,P>, | ||||
P extends TextParagraph<S,P,?> | P extends TextParagraph<S,P,?> | ||||
> extends Shape<S,P>, PlaceableShape<S,P> { | > extends Shape<S,P>, PlaceableShape<S,P> { | ||||
/** | |||||
* Return the maximum number of columns. | |||||
* If the table contains merged cells, the number of columns might be less than the maximum. | |||||
* | |||||
* @return the maximum number of column | |||||
*/ | |||||
int getNumberOfColumns(); | int getNumberOfColumns(); | ||||
/** | |||||
* Return the number of rows | |||||
* | |||||
* @return the row count | |||||
*/ | |||||
int getNumberOfRows(); | int getNumberOfRows(); | ||||
/** | |||||
* Gets a cell | |||||
* | |||||
* @param row the row index (0-based) | |||||
* @param col the column index (0-based) | |||||
* @return the cell or null if the cell doesn't exists, e.g. when accessing | |||||
* a merged cell or if the index is out of bounds | |||||
*/ | |||||
TableCell<S,P> getCell(int row, int col); | TableCell<S,P> getCell(int row, int col); | ||||
/** | /** |
private CTTable _table; | private CTTable _table; | ||||
private List<XSLFTableRow> _rows; | private List<XSLFTableRow> _rows; | ||||
@SuppressWarnings("deprecation") | |||||
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ | /*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ | ||||
super(shape, sheet); | super(shape, sheet); | ||||
@Override | @Override | ||||
public XSLFTableCell getCell(int row, int col) { | public XSLFTableCell getCell(int row, int col) { | ||||
return getRows().get(row).getCells().get(col); | |||||
List<XSLFTableRow> rows = getRows(); | |||||
if (row < 0 || rows.size() <= row) { | |||||
return null; | |||||
} | |||||
XSLFTableRow r = rows.get(row); | |||||
if (r == null) { | |||||
// empty row | |||||
return null; | |||||
} | |||||
List<XSLFTableCell> cells = r.getCells(); | |||||
if (col < 0 || cells.size() <= col) { | |||||
return null; | |||||
} | |||||
// cell can be potentially empty ... | |||||
return cells.get(col); | |||||
} | } | ||||
@Internal | @Internal |
for (EscherProperty ep : props) { | for (EscherProperty ep : props) { | ||||
if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES | if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES | ||||
&& ep instanceof EscherSimpleProperty | && ep instanceof EscherSimpleProperty | ||||
&& ((EscherSimpleProperty)ep).getPropertyValue() == 1) { | |||||
&& (((EscherSimpleProperty)ep).getPropertyValue() & 1) == 1) { | |||||
isTable = true; | isTable = true; | ||||
break; | break; | ||||
} | } |
protected HSLFTableCell[][] cells; | protected HSLFTableCell[][] cells; | ||||
private int columnCount = -1; | |||||
/** | /** | ||||
* Create a new Table of the given number of rows and columns | * Create a new Table of the given number of rows and columns | ||||
super(escherRecord, parent); | super(escherRecord, parent); | ||||
} | } | ||||
/** | |||||
* Gets a cell | |||||
* | |||||
* @param row the row index (0-based) | |||||
* @param col the column index (0-based) | |||||
* @return the cell | |||||
*/ | |||||
@Override | |||||
public HSLFTableCell getCell(int row, int col) { | public HSLFTableCell getCell(int row, int col) { | ||||
return cells[row][col]; | |||||
if (row < 0 || cells.length <= row) { | |||||
return null; | |||||
} | |||||
HSLFTableCell[] r = cells[row]; | |||||
if (r == null || col < 0 || r.length <= col) { | |||||
// empty row | |||||
return null; | |||||
} | |||||
// cell can be potentially empty ... | |||||
return r[col]; | |||||
} | } | ||||
@Override | @Override | ||||
public int getNumberOfColumns() { | public int getNumberOfColumns() { | ||||
return cells[0].length; | |||||
if (columnCount == -1) { | |||||
// check all rows in case of merged rows | |||||
for (HSLFTableCell[] hc : cells) { | |||||
if (hc != null) { | |||||
columnCount = Math.max(columnCount, hc.length); | |||||
} | |||||
} | |||||
} | |||||
return columnCount; | |||||
} | } | ||||
@Override | @Override |
ex.close(); | ex.close(); | ||||
} | } | ||||
} | } | ||||
@Test | |||||
public void bug58733() throws IOException { | |||||
File sample = HSLFTestDataSamples.getSampleFile("bug58733_671884.ppt"); | |||||
PowerPointExtractor ex = new PowerPointExtractor(sample.getAbsolutePath()); | |||||
assertNotNull(ex.getText()); | |||||
ex.close(); | |||||
} | |||||
private static HSLFSlideShow open(String fileName) throws IOException { | private static HSLFSlideShow open(String fileName) throws IOException { | ||||
File sample = HSLFTestDataSamples.getSampleFile(fileName); | File sample = HSLFTestDataSamples.getSampleFile(fileName); |