poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gal...@apache.org
Subject svn commit: r1852246 - in /poi/trunk/src: examples/src/org/apache/poi/hssf/usermodel/examples/ java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/ss/formula/fun...
Date Sat, 26 Jan 2019 19:41:25 GMT
Author: gallon
Date: Sat Jan 26 19:41:25 2019
New Revision: 1852246

URL: http://svn.apache.org/viewvc?rev=1852246&view=rev
Log:
made call Cell.setCellType(CellType.FORMULA) illegall. Deprecated Cell.setCellType(). Purged
all redundant calls from project.

Modified:
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
    poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/RangeCopier.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java (original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java Sat Jan
26 19:41:25 2019
@@ -24,7 +24,7 @@ import java.util.Date;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.FormulaError;
 
 public class CellTypes {
     public static void main(String[] args) throws IOException {
@@ -35,7 +35,7 @@ public class CellTypes {
             row.createCell(1).setCellValue(new Date());
             row.createCell(2).setCellValue("a string");
             row.createCell(3).setCellValue(true);
-            row.createCell(4).setCellType(CellType.ERROR);
+            row.createCell(4).setCellErrorValue(FormulaError.NUM);
 
             // Write the output to a file
             try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {

Modified: poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
Sat Jan 26 19:41:25 2019
@@ -24,7 +24,6 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.ss.usermodel.CellType;
 
 /**
  * Test if hyperlink formula, with url that got more than 127 characters, works
@@ -36,7 +35,6 @@ public class HyperlinkFormula {
             HSSFRow row = sheet.createRow(0);
 
             HSSFCell cell = row.createCell(0);
-            cell.setCellType(CellType.FORMULA);
             cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",
\"test\")");
 
             try (FileOutputStream fileOut = new FileOutputStream("workbook.xls")) {

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java Sat Jan 26 19:41:25 2019
@@ -292,8 +292,6 @@ public class HSSFCell extends CellBase {
                 }
                 if (getCellType() == CellType.BLANK) {
                     frec.getFormulaRecord().setValue(0);
-                } else if (setValue) {
-                    frec.getFormulaRecord().setValue(getNumericCellValue());
                 }
                 frec.setXFIndex(styleIndex);
                 _record = frec;

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Cell.java Sat Jan 26 19:41:25 2019
@@ -78,15 +78,22 @@ public interface Cell {
      * <p>to NUMERIC: numeric value is left as is. True converts to 1.0, false converts
to 0. otherwise, the
      * value is set to 0. Formula is removed.</p>
      * <p>If what you want to do is get a String value for your
-     *  numeric cell, <i>stop!</i>. This is not the way to do it.
+     *  numeric cell, <i>stop!</i> This is not the way to do it.
      *  Instead, for fetching the string value of a numeric or boolean
      *  or date cell, use {@link DataFormatter} instead.</p>
      * <p>If cell is a member of an array formula group containing more than 1 cell,
an {@link IllegalStateException}
-     * is thrown. If the array formula group contains only this cell, it is removed</p>
-     * @throws IllegalArgumentException if the specified cell type is invalid (null or _NONE)
+     * is thrown. If the array formula group contains only this cell, it is removed.</p>
+     * <p>Passing {@link CellType#FORMULA} is illegal and will result in an {@link
IllegalArgumentException}.</p>
+     *
+     * @deprecated This method is deprecated and will be removed in POI 5.0.
+     * Use explicit {@link #setCellFormula(String)}, <code>setCellValue(...)</code>
or {@link #setBlank()}
+     * to get the desired result.
+     * @throws IllegalArgumentException if the specified cell type is invalid (null, _NONE
or FORMULA)
      * @throws IllegalStateException if the current value cannot be converted to the new
type or
      * if the cell is a part of an array formula group containing other cells
      */
+    @Deprecated
+    @Removal(version = "5.0")
     void setCellType(CellType cellType);
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/CellBase.java Sat Jan 26 19:41:25 2019
@@ -35,6 +35,15 @@ public abstract class CellBase implement
             throw new IllegalArgumentException("cellType shall not be null nor _NONE");
         }
 
+        if (cellType == CellType.FORMULA) {
+            if (getCellType() != CellType.FORMULA){
+                throw new IllegalArgumentException("Calling Cell.setCellType(CellType.FORMULA)
is illegal. " +
+                        "Use setCellFormula(String) directly.");
+            } else {
+                return;
+            }
+        }
+
         tryToDeleteArrayFormulaIfSet();
 
         setCellTypeImpl(cellType);

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/RangeCopier.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/RangeCopier.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/RangeCopier.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/RangeCopier.java Sat Jan 26 19:41:25 2019
@@ -94,9 +94,9 @@ public abstract class RangeCopier {
                     destRow = destSheet.createRow(rowNo + deltaY);
                 
                 Cell newCell = destRow.getCell(columnIndex + deltaX);
-                if(newCell != null)
-                    newCell.setCellType(sourceCell.getCellType());
-                else newCell = destRow.createCell(columnIndex + deltaX, sourceCell.getCellType());
+                if(newCell == null) {
+                    newCell = destRow.createCell(columnIndex + deltaX);
+                }
 
                 cloneCellContent(sourceCell, newCell, null);
                 if(newCell.getCellType() == CellType.FORMULA)

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java Sat Jan 26
19:41:25 2019
@@ -425,8 +425,6 @@ public class XSSFPivotTable extends POIX
     private void addDataField(DataConsolidateFunction function, int columnIndex, String valueFieldName,
String valueFormat) {
         checkColumnIndex(columnIndex);
         
-        AreaReference pivotArea = getPivotArea();
-        
         CTDataFields dataFields;
         if(pivotTableDefinition.getDataFields() != null) {
             dataFields = pivotTableDefinition.getDataFields();
@@ -435,9 +433,6 @@ public class XSSFPivotTable extends POIX
         }
         CTDataField dataField = dataFields.addNewDataField();
         dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));
-        Cell cell = getDataSheet().getRow(pivotArea.getFirstCell().getRow())
-                .getCell(pivotArea.getFirstCell().getCol() + columnIndex);
-        cell.setCellType(CellType.STRING);
         dataField.setName(valueFieldName);
         dataField.setFld(columnIndex);
         if (valueFormat != null && !valueFormat.trim().isEmpty()) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java Sat Jan 26 19:41:25
2019
@@ -28,6 +28,7 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellCopyPolicy;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.FormulaError;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.helpers.RowShifter;
 import org.apache.poi.ss.util.CellRangeAddress;
@@ -220,12 +221,33 @@ public class XSSFRow implements Row, Com
         }
         XSSFCell xcell = new XSSFCell(this, ctCell);
         xcell.setCellNum(columnIndex);
-        if (type != CellType.BLANK) {
-            xcell.setCellType(type);
+        if (type != CellType.BLANK && type != CellType.FORMULA) {
+            setDefaultValue(xcell, type);
         }
+
         _cells.put(colI, xcell);
         return xcell;
     }
+
+    private static void setDefaultValue(XSSFCell cell, CellType type) {
+        switch (type) {
+            case NUMERIC:
+                cell.setCellValue(0);
+                break;
+            case STRING:
+                cell.setCellValue("");
+                break;
+            case BOOLEAN:
+                cell.setCellValue(false);
+                break;
+            case ERROR:
+                cell.setCellErrorValue(FormulaError._NO_ERROR);
+                break;
+            default:
+                throw new AssertionError();
+        }
+    }
+
     /**
      * Returns the cell at the given (0 based) index,
      *  with the {@link org.apache.poi.ss.usermodel.Row.MissingCellPolicy} from the parent
Workbook.
@@ -588,7 +610,7 @@ public class XSSFRow implements Row, Com
         else {
             for (final Cell c : srcRow){
                 final XSSFCell srcCell = (XSSFCell)c;
-                final XSSFCell destCell = createCell(srcCell.getColumnIndex(), srcCell.getCellType());
+                final XSSFCell destCell = createCell(srcCell.getColumnIndex());
                 destCell.copyCellFrom(srcCell, policy);
             }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java Sat
Jan 26 19:41:25 2019
@@ -59,7 +59,6 @@ public final class TestProper {
     private void confirm(Workbook wb) {
         Sheet sheet = wb.createSheet("new sheet");
         cell11 = sheet.createRow(0).createCell(0);
-        cell11.setCellType(CellType.FORMULA);
 
         confirm("PROPER(\"hi there\")", "Hi There"); //simple case
         confirm("PROPER(\"what's up\")", "What'S Up"); //apostrophes are treated as word
breaks

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java Sat
Jan 26 19:41:25 2019
@@ -537,20 +537,16 @@ public final class TestXSSFExportToXML {
        
        Cell cFormulaString = row.createCell(3);
        cFormulaString.setCellFormula("A1");
-       cFormulaString.setCellType(CellType.FORMULA);
-       
+
        Cell cFormulaNumeric = row.createCell(4);
        cFormulaNumeric.setCellFormula("F1");
-       cFormulaNumeric.setCellType(CellType.FORMULA);
-       
+
        Cell cNumeric = row.createCell(5);
        cNumeric.setCellValue(1.2);
-       cNumeric.setCellType(CellType.NUMERIC);
-       
+
        Cell cDate = row.createCell(6);
        cDate.setCellValue(new Date());
-       cDate.setCellType(CellType.NUMERIC);
-       
+
        boolean found = false;
        for (POIXMLDocumentPart p : wb.getRelations()) {
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java Sat Jan
26 19:41:25 2019
@@ -187,4 +187,9 @@ public class TestSXSSFCell extends BaseT
     @Ignore
     public void setCellFormula_isExceptionSafe_onBlankCell() {
     }
+
+    @Test
+    @Ignore
+    public void setCellType_FORMULA_onAnArrayFormulaCell_doesNothing() {
+    }
 }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java Sat Jan
26 19:41:25 2019
@@ -626,7 +626,7 @@ public final class TestXSSFBugs extends
         // Otherwise should go
         sheet.getRow(1).getCell(0).setCellFormula("A1"); // stay
         sheet.getRow(2).getCell(0).setCellFormula(null); // go
-        sheet.getRow(3).getCell(0).setCellType(CellType.FORMULA); // stay
+        sheet.getRow(3).getCell(0).setCellFormula("14"); // stay
         XSSFTestDataSamples.writeOutAndReadBack(wb1).close();
 
         sheet.getRow(4).getCell(0).setCellType(CellType.STRING); // go

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java Sat Jan
26 19:41:25 2019
@@ -217,7 +217,6 @@ public final class TestHSSFDataFormatter
         { // formula cell
             row = sheet.createRow(7);
             HSSFCell cell = row.createCell(0);
-            cell.setCellType(CellType.FORMULA);
             cell.setCellFormula("SUM(12.25,12.25)/100");
             HSSFCellStyle cellStyle = wb.createCellStyle();
             cellStyle.setDataFormat(format.getFormat("##.00%;"));

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestCalendarFieldFunction.java
Sat Jan 26 19:41:25 2019
@@ -40,7 +40,6 @@ public final class TestCalendarFieldFunc
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sheet = wb.createSheet("new sheet");
         cell11 = sheet.createRow(0).createCell(0);
-        cell11.setCellType(CellType.FORMULA);
         evaluator = new HSSFFormulaEvaluator(wb);
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDate.java Sat Jan 26 19:41:25
2019
@@ -40,7 +40,6 @@ public final class TestDate extends Test
         HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet sheet = wb.createSheet("new sheet");
         cell11 = sheet.createRow(0).createCell(0);
-        cell11.setCellType(CellType.FORMULA);
         evaluator = new HSSFFormulaEvaluator(wb);
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestFixed.java Sat Jan 26
19:41:25 2019
@@ -48,7 +48,6 @@ public final class TestFixed {
         try {
             HSSFSheet sheet = wb.createSheet("new sheet");
             cell11 = sheet.createRow(0).createCell(0);
-            cell11.setCellType(CellType.FORMULA);
             evaluator = new HSSFFormulaEvaluator(wb);
         } finally {
             wb.close();

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java Sat Jan
26 19:41:25 2019
@@ -1218,8 +1218,7 @@ public abstract class BaseTestBugzillaIs
                 value == null || value.length() == 0);
 
         cell = row.createCell(1);
-        // also verify that setting formulas to null works
-        cell.setCellType(CellType.FORMULA);
+        cell.setCellFormula("0");
         cell.setCellValue((String)null);
 
         wb.getCreationHelper().createFormulaEvaluator().evaluateAll();

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Sat Jan 26 19:41:25
2019
@@ -1358,6 +1358,38 @@ public abstract class BaseTestCell {
         assertTrue(cell.getBooleanCellValue());
     }
 
+    @Test(expected = IllegalArgumentException.class)
+    public void setCellType_FORMULA_onANonFormulaCell_throwsIllegalArgumentException() {
+        Cell cell = getInstance();
+        cell.setCellType(CellType.FORMULA);
+    }
+
+    @Test
+    public void setCellType_FORMULA_onAFormulaCell_doesNothing() {
+        Cell cell = getInstance();
+        cell.setCellFormula("3");
+        cell.setCellValue("foo");
+
+        cell.setCellType(CellType.FORMULA);
+
+        assertEquals(CellType.FORMULA, cell.getCellType());
+        assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
+        assertEquals("foo", cell.getStringCellValue());
+    }
+
+    @Test
+    public void setCellType_FORMULA_onAnArrayFormulaCell_doesNothing() {
+        Cell cell = getInstance();
+        cell.getSheet().setArrayFormula("3", CellRangeAddress.valueOf("A1:A2"));
+        cell.setCellValue("foo");
+
+        cell.setCellType(CellType.FORMULA);
+
+        assertEquals(CellType.FORMULA, cell.getCellType());
+        assertEquals(CellType.STRING, cell.getCachedFormulaResultType());
+        assertEquals("foo", cell.getStringCellValue());
+    }
+
     @Test
     public final void setBlank_delegatesTo_setCellType_BLANK() {
         Cell cell = mock(CellBase.class);

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java?rev=1852246&r1=1852245&r2=1852246&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java Sat
Jan 26 19:41:25 2019
@@ -384,12 +384,10 @@ public abstract class BaseTestFormulaEva
 
             // sheet1 A2 formulae
             cell = sheet1.createRow(1).createCell(0);
-            cell.setCellType(CellType.FORMULA);
             cell.setCellFormula("SUM(Sheet1:Sheet3!A1)");
 
             // sheet1 A3 formulae
             cell = sheet1.createRow(2).createCell(0);
-            cell.setCellType(CellType.FORMULA);
             cell.setCellFormula("SUM(Sheet1:Sheet3!A1:B1)");
 
             wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
@@ -589,7 +587,6 @@ public abstract class BaseTestFormulaEva
         if (cell == null) {
             cell = r.createCell(column);
         }
-        cell.setCellType(CellType.FORMULA);
         cell.setCellFormula(formula);
     }
 



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


Mime
View raw message