You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/03/30 18:25:56 UTC
svn commit: r642769 - in /poi/branches/ooxml: ./
src/java/org/apache/poi/hssf/record/
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/
src/ooxml/java/org/apache/poi/xssf/usermodel/
src/ooxml/testcases/org/apache/poi/xssf/usermodel/
Author: nick
Date: Sun Mar 30 09:25:52 2008
New Revision: 642769
URL: http://svn.apache.org/viewvc?rev=642769&view=rev
Log:
Improve how XSSFCell does error stuff
Modified:
poi/branches/ooxml/build.xml
poi/branches/ooxml/src/java/org/apache/poi/hssf/record/BoolErrRecord.java
poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
Modified: poi/branches/ooxml/build.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/build.xml?rev=642769&r1=642768&r2=642769&view=diff
==============================================================================
--- poi/branches/ooxml/build.xml (original)
+++ poi/branches/ooxml/build.xml Sun Mar 30 09:25:52 2008
@@ -544,6 +544,7 @@
<classpath>
<path refid="ooxml.classpath"/>
<pathelement path="${ooxml.output.dir}"/>
+ <pathelement path="${main.output.test.dir}"/>
<pathelement location="${junit.jar1.dir}"/>
</classpath>
</javac>
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/BoolErrRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/BoolErrRecord.java?rev=642769&r1=642768&r2=642769&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/BoolErrRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/BoolErrRecord.java Sun Mar 30 09:25:52 2008
@@ -46,14 +46,6 @@
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()
{
Modified: poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java?rev=642769&r1=642768&r2=642769&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Cell.java Sun Mar 30 09:25:52 2008
@@ -70,6 +70,26 @@
*/
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)
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=642769&r1=642768&r2=642769&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sun Mar 30 09:25:52 2008
@@ -20,7 +20,6 @@
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;
@@ -28,6 +27,8 @@
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;
@@ -44,6 +45,8 @@
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.
@@ -154,7 +157,7 @@
}
/**
* 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()) {
@@ -162,25 +165,25 @@
}
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;
}
@@ -224,13 +227,32 @@
}
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) {
Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=642769&r1=642768&r2=642769&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sun Mar 30 09:25:52 2008
@@ -120,12 +120,10 @@
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();
@@ -133,17 +131,30 @@
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
Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java?rev=642769&r1=642768&r2=642769&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java Sun Mar 30 09:25:52 2008
@@ -109,10 +109,18 @@
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 {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org