S extends Shape<S,P>,\r
P extends TextParagraph<S,P,?>\r
> extends Shape<S,P>, PlaceableShape<S,P> {\r
+ /**\r
+ * Return the maximum number of columns.\r
+ * If the table contains merged cells, the number of columns might be less than the maximum.\r
+ *\r
+ * @return the maximum number of column\r
+ */\r
int getNumberOfColumns();\r
\r
+ /**\r
+ * Return the number of rows\r
+ *\r
+ * @return the row count\r
+ */\r
int getNumberOfRows();\r
\r
+ /**\r
+ * Gets a cell\r
+ *\r
+ * @param row the row index (0-based)\r
+ * @param col the column index (0-based)\r
+ * @return the cell or null if the cell doesn't exists, e.g. when accessing\r
+ * a merged cell or if the index is out of bounds\r
+ */\r
TableCell<S,P> getCell(int row, int col);\r
\r
/**\r
private CTTable _table;\r
private List<XSLFTableRow> _rows;\r
\r
- @SuppressWarnings("deprecation")\r
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){\r
super(shape, sheet);\r
\r
\r
@Override\r
public XSLFTableCell getCell(int row, int col) {\r
- return getRows().get(row).getCells().get(col);\r
+ List<XSLFTableRow> rows = getRows();\r
+ if (row < 0 || rows.size() <= row) {\r
+ return null;\r
+ }\r
+ XSLFTableRow r = rows.get(row);\r
+ if (r == null) {\r
+ // empty row\r
+ return null;\r
+ }\r
+ List<XSLFTableCell> cells = r.getCells();\r
+ if (col < 0 || cells.size() <= col) {\r
+ return null;\r
+ }\r
+ // cell can be potentially empty ...\r
+ return cells.get(col);\r
}\r
\r
@Internal\r
for (EscherProperty ep : props) {
if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES
&& ep instanceof EscherSimpleProperty
- && ((EscherSimpleProperty)ep).getPropertyValue() == 1) {
+ && (((EscherSimpleProperty)ep).getPropertyValue() & 1) == 1) {
isTable = true;
break;
}
protected HSLFTableCell[][] cells;
+ private int columnCount = -1;
/**
* Create a new Table of the given number of rows and columns
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) {
- 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
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
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 {
File sample = HSLFTestDataSamples.getSampleFile(fileName);