Author: nick
Date: Thu Oct 31 16:53:03 2013
New Revision: 1537552

URL: http://svn.apache.org/r1537552
Log:
Allow formatting of formula error cells, giving back the error string that 
Excel shows #55729

Modified:
    poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=1537552&r1=1537551&r2=1537552&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Thu Oct 
31 16:53:03 2013
@@ -829,6 +829,8 @@ public class DataFormatter {
                 return String.valueOf(cell.getBooleanCellValue());
             case Cell.CELL_TYPE_BLANK :
                 return "";
+            case Cell.CELL_TYPE_ERROR:
+               return 
FormulaError.forInt(cell.getErrorCellValue()).getString();
         }
         throw new RuntimeException("Unexpected celltype (" + cellType + ")");
     }

Modified: 
poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java?rev=1537552&r1=1537551&r2=1537552&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java 
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java 
Thu Oct 31 16:53:03 2013
@@ -28,6 +28,7 @@ import java.util.Locale;
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
 
 /**
@@ -491,6 +492,22 @@ public class TestDataFormatter extends T
         assertEquals(" -   ", dfUS.formatRawCellContents(0.0, -1, "_-* 
#,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
         assertEquals(" $-   ", dfUS.formatRawCellContents(0.0, -1, "_-$* 
#,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
     }
+    
+    public void testErrors() {
+        DataFormatter dfUS = new DataFormatter(Locale.US, true);
+
+        // Create a spreadsheet with some formula errors in it
+        Workbook wb = new HSSFWorkbook();
+        Sheet s = wb.createSheet();
+        Row r = s.createRow(0);
+        Cell c = r.createCell(0, Cell.CELL_TYPE_ERROR);
+        
+        c.setCellErrorValue(FormulaError.DIV0.getCode());
+        assertEquals(FormulaError.DIV0.getString(), dfUS.formatCellValue(c));
+        
+        c.setCellErrorValue(FormulaError.REF.getCode());
+        assertEquals(FormulaError.REF.getString(), dfUS.formatCellValue(c));
+    }
 
     /**
      * TODO Fix these so that they work



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to