==================================================================== */
package org.apache.poi.hssf.usermodel;
-import org.apache.poi.ddf.*;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.ddf.DefaultEscherRecordFactory;
+import org.apache.poi.ddf.EscherBSERecord;
+import org.apache.poi.ddf.EscherContainerRecord;
+import org.apache.poi.ddf.EscherOptRecord;
+import org.apache.poi.ddf.EscherProperties;
+import org.apache.poi.ddf.EscherSimpleProperty;
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
+import org.apache.poi.hssf.record.EndSubRecord;
+import org.apache.poi.hssf.record.NoteRecord;
+import org.apache.poi.hssf.record.NoteStructureSubRecord;
+import org.apache.poi.hssf.record.ObjRecord;
+import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.ss.usermodel.Comment;
/**
protected NoteRecord getNoteRecord() {
return _note;
}
+
+ /**
+ * Do we know which cell this comment belongs to?
+ */
+ public boolean hasPosition() {
+ if (_note == null) return false;
+ if (getColumn() < 0 || getRow() < 0) return false;
+ return true;
+ }
@Override
public void setShapeType(int shapeType) {
import org.apache.poi.hssf.model.HSSFFormulaParser;
import org.apache.poi.hssf.model.InternalSheet;
import org.apache.poi.hssf.model.InternalWorkbook;
-import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.record.AutoFilterInfoRecord;
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.DVRecord;
+import org.apache.poi.hssf.record.DimensionsRecord;
+import org.apache.poi.hssf.record.DrawingRecord;
+import org.apache.poi.hssf.record.EscherAggregate;
+import org.apache.poi.hssf.record.ExtendedFormatRecord;
+import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.NoteRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RowRecord;
+import org.apache.poi.hssf.record.SCLRecord;
+import org.apache.poi.hssf.record.WSBoolRecord;
+import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
}
if (shape instanceof HSSFComment) {
HSSFComment comment = (HSSFComment) shape;
- if (comment.getColumn() == column && comment.getRow() == row) {
+ if (comment.hasPosition() && comment.getColumn() == column && comment.getRow() == row) {
return comment;
}
}
assertAlmostEquals(1950, s.getColumnWidth(10), fontAccuracy);
assertAlmostEquals(2225, s.getColumnWidth(11), fontAccuracy);
}
+
+ @Test
+ public void bug56450() {
+ HSSFWorkbook wb = openSample("56450.xls");
+ HSSFSheet sheet = wb.getSheetAt(0);
+ int comments = 0;
+ for (Row r : sheet) {
+ for (Cell c : r) {
+ if (c.getCellComment() != null) {
+ assertNotNull(c.getCellComment().getString().getString());
+ comments++;
+ }
+ }
+ }
+ assertEquals(0, comments);
+ }
}