<classpath>
<path refid="ooxml.classpath"/>
<pathelement path="${ooxml.output.dir}"/>
+ <pathelement path="${main.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
</javac>
private byte field_4_bBoolErr;
private byte field_5_fError;
- public static final byte NULL = 0;
- public static final byte DIV0 = 7;
- public static final byte VALUE = 15;
- public static final byte REF = 23;
- public static final byte NAME = 29;
- public static final byte NUM = 36;
- public static final byte NA = 42;
-
/** Creates new BoolErrRecord */
public BoolErrRecord()
{
*/
public final static int CELL_TYPE_ERROR = 5;
+
+ public final static class CELL_ERROR_TYPE {
+ private final byte type;
+ private final String repr;
+ private CELL_ERROR_TYPE(int type, String repr) {
+ this.type = (byte)type;
+ this.repr = repr;
+ }
+
+ public byte getType() { return type; }
+ public String getStringRepr() { return repr; }
+ }
+ public static final CELL_ERROR_TYPE ERROR_NULL = new CELL_ERROR_TYPE(0, "#NULL!");
+ public static final CELL_ERROR_TYPE ERROR_DIV0 = new CELL_ERROR_TYPE(7, "#DIV/0!");
+ public static final CELL_ERROR_TYPE ERROR_VALUE = new CELL_ERROR_TYPE(15, "#VALUE!");
+ public static final CELL_ERROR_TYPE ERROR_REF = new CELL_ERROR_TYPE(23, "#REF!");
+ public static final CELL_ERROR_TYPE ERROR_NAME = new CELL_ERROR_TYPE(29, "#NAME?");
+ public static final CELL_ERROR_TYPE ERROR_NUM = new CELL_ERROR_TYPE(36, "#NUM!");
+ public static final CELL_ERROR_TYPE ERROR_NA = new CELL_ERROR_TYPE(42, "#N/A");
+
/**
* set the cell's number within the row (0 based)
import java.util.Calendar;
import java.util.Date;
-import org.apache.poi.hssf.record.BoolErrRecord;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.SharedStringSource;
import org.apache.poi.ss.usermodel.StylesSource;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.util.CellReference;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
private SharedStringSource sharedStringSource;
private StylesSource stylesSource;
+ private POILogger logger = POILogFactory.getLogger(XSSFCell.class);
+
/**
* Create a new XSSFCell. This method is protected to be used only by
* tests.
}
/**
* Returns the error type, in the same way that
- * HSSFCell does. See {@link BoolErrRecord} for details
+ * HSSFCell does. See {@link Cell} for details
*/
public byte getErrorCellValue() {
if (STCellType.E != cell.getT()) {
}
if (this.cell.isSetV()) {
String errS = this.cell.getV();
- if(errS.equals("#NULL!")) {
- return BoolErrRecord.NULL;
+ if(errS.equals(Cell.ERROR_NULL.getStringRepr())) {
+ return Cell.ERROR_NULL.getType();
}
- if(errS.equals("#DIV/0!")) {
- return BoolErrRecord.DIV0;
+ if(errS.equals(Cell.ERROR_DIV0.getStringRepr())) {
+ return Cell.ERROR_DIV0.getType();
}
- if(errS.equals("#VALUE!")) {
- return BoolErrRecord.VALUE;
+ if(errS.equals(Cell.ERROR_VALUE.getStringRepr())) {
+ return Cell.ERROR_VALUE.getType();
}
- if(errS.equals("#REF!")) {
- return BoolErrRecord.REF;
+ if(errS.equals(Cell.ERROR_REF.getStringRepr())) {
+ return Cell.ERROR_REF.getType();
}
- if(errS.equals("#NAME?")) {
- return BoolErrRecord.NAME;
+ if(errS.equals(Cell.ERROR_NAME.getStringRepr())) {
+ return Cell.ERROR_NAME.getType();
}
- if(errS.equals("#NUM!")) {
- return BoolErrRecord.NUM;
+ if(errS.equals(Cell.ERROR_NUM.getStringRepr())) {
+ return Cell.ERROR_NUM.getType();
}
- return BoolErrRecord.NA;
+ return Cell.ERROR_NA.getType();
}
return 0;
}
}
public void setCellErrorValue(byte value) {
+ if(value == Cell.ERROR_DIV0.getType()) {
+ setCellErrorValue(Cell.ERROR_DIV0);
+ } else if(value == Cell.ERROR_NA.getType()) {
+ setCellErrorValue(Cell.ERROR_NA);
+ } else if(value == Cell.ERROR_NAME.getType()) {
+ setCellErrorValue(Cell.ERROR_NAME);
+ } else if(value == Cell.ERROR_NULL.getType()) {
+ setCellErrorValue(Cell.ERROR_NULL);
+ } else if(value == Cell.ERROR_NUM.getType()) {
+ setCellErrorValue(Cell.ERROR_NUM);
+ } else if(value == Cell.ERROR_REF.getType()) {
+ setCellErrorValue(Cell.ERROR_REF);
+ } else if(value == Cell.ERROR_VALUE.getType()) {
+ setCellErrorValue(Cell.ERROR_VALUE);
+ } else {
+ logger.log(POILogger.WARN, "Unknown error type " + value + " specified, treating as #N/A");
+ setCellErrorValue(Cell.ERROR_NA);
+ }
+ }
+ public void setCellErrorValue(CELL_ERROR_TYPE errorType) {
if ((this.cell.getT() != STCellType.E) && (this.cell.getT() != STCellType.STR))
{
this.cell.setT(STCellType.E);
}
- this.cell.setV(String.valueOf(value));
+ this.cell.setV( errorType.getStringRepr() );
}
-
public void setCellFormula(String formula) {
public String getDefaultFileName() { return DEFAULT_NAME; }
/**
- * Load, off the specified core part
+ * Fetches the InputStream to read the contents, based
+ * of the specified core part
*/
- private XSSFModel load(PackagePart corePart) throws Exception {
- Constructor<? extends XSSFModel> c = CLASS.getConstructor(InputStream.class);
- XSSFModel model = null;
-
+ public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
PackageRelationshipCollection prc =
corePart.getRelationshipsByType(REL);
Iterator<PackageRelationship> it = prc.iterator();
PackageRelationship rel = it.next();
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
PackagePart part = corePart.getPackage().getPart(relName);
- InputStream is = part.getInputStream();
+ return part.getInputStream();
+ } else {
+ log.log(POILogger.WARN, "No part " + DEFAULT_NAME + " found");
+ return null;
+ }
+ }
+ /**
+ * Load, off the specified core part
+ */
+ public XSSFModel load(PackagePart corePart) throws Exception {
+ Constructor<? extends XSSFModel> c = CLASS.getConstructor(InputStream.class);
+ XSSFModel model = null;
+
+ InputStream inp = getContents(corePart);
+ if(inp != null) {
try {
- model = c.newInstance(is);
+ model = c.newInstance(inp);
} finally {
- is.close();
+ inp.close();
}
- } else {
- log.log(POILogger.WARN, "No part " + DEFAULT_NAME + " found");
}
return model;
}
+
/**
* Save, with the default name
* @return The internal reference ID it was saved at, normally then used as an r:id
public void testSetGetError() throws Exception {
XSSFRow row = createParentObjects();
XSSFCell cell = new XSSFCell(row);
- cell.setCellErrorValue((byte)255);
+
+ cell.setCellErrorValue((byte)0);
assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType());
-
- assertEquals((byte)255, cell.getErrorCellValue());
+ assertEquals((byte)0, cell.getErrorCellValue());
+
+ cell.setCellValue(2.2);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+
+ cell.setCellErrorValue(Cell.ERROR_NAME);
+ assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType());
+ assertEquals(Cell.ERROR_NAME.getType(), cell.getErrorCellValue());
+ assertEquals(Cell.ERROR_NAME.getStringRepr(), cell.getErrorCellString());
}
public void testSetGetFormula() throws Exception {